mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:55:07 +02:00
Custom command attributes (#14906)
# Description Add custom command attributes. - Attributes are placed before a command definition and start with a `@` character. - Attribute invocations consist of const command call. The command's name must start with "attr ", but this prefix is not used in the invocation. - A command named `attr example` is invoked as an attribute as `@example` - Several built-in attribute commands are provided as part of this PR - `attr example`: Attaches an example to the commands help text ```nushell # Double numbers @example "double an int" { 5 | double } --result 10 @example "double a float" { 0.5 | double } --result 1.0 def double []: [number -> number] { $in * 2 } ``` - `attr search-terms`: Adds search terms to a command - ~`attr env`: Equivalent to using `def --env`~ - ~`attr wrapped`: Equivalent to using `def --wrapped`~ shelved for later discussion - several testing related attributes in `std/testing` - If an attribute has no internal/special purpose, it's stored as command metadata that can be obtained with `scope commands`. - This allows having attributes like `@test` which can be used by test runners. - Used the `@example` attribute for `std` examples. - Updated the std tests and test runner to use `@test` attributes - Added completions for attributes # User-Facing Changes Users can add examples to their own command definitions, and add other arbitrary attributes. # Tests + Formatting - 🟢 toolkit fmt - 🟢 toolkit clippy - 🟢 toolkit test - 🟢 toolkit test stdlib # After Submitting - Add documentation about the attribute syntax and built-in attributes - `help attributes` --------- Co-authored-by: 132ikl <132@ikl.sh>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
|
||||
def run [
|
||||
@ -41,57 +42,57 @@ def "assert message short" [
|
||||
assert str contains $output "test message"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def critical [] {
|
||||
assert no message 99 critical
|
||||
assert message CRITICAL critical CRT
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def critical_short [] {
|
||||
assert message short CRITICAL critical C
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def error [] {
|
||||
assert no message CRITICAL error
|
||||
assert message ERROR error ERR
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def error_short [] {
|
||||
assert message short ERROR error E
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def warning [] {
|
||||
assert no message ERROR warning
|
||||
assert message WARNING warning WRN
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def warning_short [] {
|
||||
assert message short WARNING warning W
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def info [] {
|
||||
assert no message WARNING info
|
||||
assert message INFO info "INF" # INF has to be quoted, otherwise it is the `inf` float
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def info_short [] {
|
||||
assert message short INFO info I
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def debug [] {
|
||||
assert no message INFO debug
|
||||
assert message DEBUG debug DBG
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def debug_short [] {
|
||||
assert message short DEBUG debug D
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use commons.nu *
|
||||
|
||||
@ -21,14 +22,14 @@ def run-command [
|
||||
| complete | get --ignore-errors stderr
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def errors_during_deduction [] {
|
||||
assert str contains (run-command "DEBUG" "msg" "%MSG%" 25) "Cannot deduce log level prefix for given log level"
|
||||
assert str contains (run-command "DEBUG" "msg" "%MSG%" 25 --ansi (ansi red)) "Cannot deduce log level prefix for given log level"
|
||||
assert str contains (run-command "DEBUG" "msg" "%MSG%" 25 --level-prefix "abc") "Cannot deduce ansi for given log level"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def valid_calls [] {
|
||||
use std/log *
|
||||
assert equal (run-command "DEBUG" "msg" "%MSG%" 25 --level-prefix "abc" --ansi (ansi default) | str trim --right) "msg"
|
||||
@ -37,7 +38,7 @@ def valid_calls [] {
|
||||
assert equal (run-command "INFO" "msg" "%ANSI_START%%LEVEL% %MSG%%ANSI_STOP%" ((log-level).CRITICAL) | str trim --right) $"((log-ansi).CRITICAL)CRT msg(ansi reset)"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def log-level_handling [] {
|
||||
use std/log *
|
||||
assert equal (run-command "DEBUG" "msg" "%LEVEL% %MSG%" 20 | str trim --right) $"((log-prefix).INFO) msg"
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std/testing *
|
||||
use std *
|
||||
use std/log *
|
||||
use std/assert
|
||||
@ -40,7 +41,7 @@ def "assert formatted" [
|
||||
assert equal ($output | str trim --right) (format-message $message $format $prefix $ansi)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def format_flag [] {
|
||||
assert formatted "test" "25 %MSG% %ANSI_START% %LEVEL%%ANSI_STOP%" critical
|
||||
assert formatted "test" "25 %MSG% %ANSI_START% %LEVEL%%ANSI_STOP%" error
|
||||
|
@ -1,8 +1,9 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use std/log
|
||||
use std/log *
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def env_log-ansi [] {
|
||||
assert equal (log-ansi).CRITICAL (ansi red_bold)
|
||||
assert equal (log-ansi).ERROR (ansi red)
|
||||
@ -11,7 +12,7 @@ def env_log-ansi [] {
|
||||
assert equal (log-ansi).DEBUG (ansi default_dimmed)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def env_log-level [] {
|
||||
assert equal (log-level).CRITICAL 50
|
||||
assert equal (log-level).ERROR 40
|
||||
@ -20,7 +21,7 @@ def env_log-level [] {
|
||||
assert equal (log-level).DEBUG 10
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def env_log-prefix [] {
|
||||
assert equal (log-prefix).CRITICAL "CRT"
|
||||
assert equal (log-prefix).ERROR "ERR"
|
||||
@ -29,7 +30,7 @@ def env_log-prefix [] {
|
||||
assert equal (log-prefix).DEBUG "DBG"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def env_log-short-prefix [] {
|
||||
assert equal (log-short-prefix).CRITICAL "C"
|
||||
assert equal (log-short-prefix).ERROR "E"
|
||||
@ -38,7 +39,7 @@ def env_log-short-prefix [] {
|
||||
assert equal (log-short-prefix).DEBUG "D"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def env_log_format [] {
|
||||
assert equal $env.NU_LOG_FORMAT $"%ANSI_START%%DATE%|%LEVEL%|%MSG%%ANSI_STOP%"
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std/testing *
|
||||
use std *
|
||||
use std/assert
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_basic [] {
|
||||
assert true
|
||||
assert (1 + 2 == 3)
|
||||
@ -9,7 +10,7 @@ def assert_basic [] {
|
||||
assert error { assert (1 + 2 == 4) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_not [] {
|
||||
assert not false
|
||||
assert not (1 + 2 == 4)
|
||||
@ -17,7 +18,7 @@ def assert_not [] {
|
||||
assert error { assert not (1 + 2 == 3) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_equal [] {
|
||||
assert equal (1 + 2) 3
|
||||
assert equal (0.1 + 0.2 | into string | into float) 0.3 # 0.30000000000000004 == 0.3
|
||||
@ -25,7 +26,7 @@ def assert_equal [] {
|
||||
assert error { assert equal (1 + 2) 4 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_not_equal [] {
|
||||
assert not equal (1 + 2) 4
|
||||
assert not equal 1 "foo"
|
||||
@ -33,7 +34,7 @@ def assert_not_equal [] {
|
||||
assert error { assert not equal 1 1 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_error [] {
|
||||
let failing_code = {|| missing_code_to_run}
|
||||
assert error $failing_code
|
||||
@ -43,39 +44,39 @@ def assert_error [] {
|
||||
assert $assert_error_raised "The assert error should be false if there is no error in the executed code."
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_less [] {
|
||||
assert less 1 2
|
||||
assert error { assert less 1 1 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_less_or_equal [] {
|
||||
assert less or equal 1 2
|
||||
assert less or equal 1 1
|
||||
assert error { assert less or equal 1 0 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_greater [] {
|
||||
assert greater 2 1
|
||||
assert error { assert greater 2 2 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_greater_or_equal [] {
|
||||
assert greater or equal 1 1
|
||||
assert greater or equal 2 1
|
||||
assert error { assert greater or equal 0 1 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_length [] {
|
||||
assert length [0, 0, 0] 3
|
||||
assert error { assert length [0, 0] 3 }
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@ignore
|
||||
def assert_skip [] {
|
||||
assert true # This test case is skipped on purpose
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use std/log
|
||||
|
||||
@ -5,7 +6,7 @@ use std/log
|
||||
# Each 'use' for that module in the test script will execute the def --env block.
|
||||
# PWD at the time of the `use` will be what the export def --env block will see.
|
||||
|
||||
#[before-each]
|
||||
@before-each
|
||||
def before-each [] {
|
||||
# need some directories to play with
|
||||
let base_path = ($nu.temp-path | path join $"test_dirs_(random uuid)")
|
||||
@ -17,7 +18,7 @@ def before-each [] {
|
||||
{base_path: $base_path, path_a: $path_a, path_b: $path_b}
|
||||
}
|
||||
|
||||
#[after-each]
|
||||
@after-each
|
||||
def after-each [] {
|
||||
let base_path = $in.base_path
|
||||
cd $base_path
|
||||
@ -36,7 +37,7 @@ def cur_ring_check [expect_dir:string, expect_position: int scenario:string] {
|
||||
assert equal $expect_position $env.DIRS_POSITION $"position in ring after ($scenario)"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def dirs_command [] {
|
||||
# careful with order of these statements!
|
||||
# must capture value of $in before executing `use`s
|
||||
@ -87,7 +88,7 @@ def dirs_command [] {
|
||||
assert equal $env.PWD $c.base_path "drop changes PWD (regression test for #9449)"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def dirs_next [] {
|
||||
# must capture value of $in before executing `use`s
|
||||
let $c = $in
|
||||
@ -109,7 +110,7 @@ def dirs_next [] {
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def dirs_cd [] {
|
||||
# must capture value of $in before executing `use`s
|
||||
let $c = $in
|
||||
@ -134,7 +135,7 @@ def dirs_cd [] {
|
||||
assert equal [$c.path_b $c.path_b] $env.DIRS_LIST "cd updated both positions in ring"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def dirs_goto_bug10696 [] {
|
||||
let $c = $in
|
||||
cd $c.base_path
|
||||
@ -148,7 +149,7 @@ def dirs_goto_bug10696 [] {
|
||||
assert equal $env.PWD $c.path_b "goto other, then goto to come back returns to same directory"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def dirs_goto [] {
|
||||
let $c = $in
|
||||
cd $c.base_path
|
||||
|
@ -1,44 +1,45 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use std/dt *
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def equal_times [] {
|
||||
let t1 = (date now)
|
||||
assert equal (datetime-diff $t1 $t1) ({year:0, month:0, day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0 nanosecond:0})
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def one_ns_later [] {
|
||||
let t1 = (date now)
|
||||
assert equal (datetime-diff ($t1 + 1ns) $t1) ({year:0, month:0, day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0 nanosecond:1})
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def one_yr_later [] {
|
||||
let t1 = ('2022-10-1T0:1:2z' | into datetime) # a date for which one year later is 365 days, since duration doesn't support year or month
|
||||
assert equal (datetime-diff ($t1 + 365day) $t1) ({year:1, month:0, day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0 nanosecond:0})
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def carry_ripples [] {
|
||||
let t1 = ('2023-10-9T0:0:0z' | into datetime)
|
||||
let t2 = ('2022-10-9T0:0:0.000000001z' | into datetime)
|
||||
assert equal (datetime-diff $t1 $t2) ({year:0, month:11, day:30, hour:23, minute:59, second:59, millisecond:999, microsecond:999 nanosecond:999})
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def earlier_arg_must_be_less_or_equal_later [] {
|
||||
let t1 = ('2022-10-9T0:0:0.000000001z' | into datetime)
|
||||
let t2 = ('2023-10-9T0:0:0z' | into datetime)
|
||||
assert error {|| (datetime-diff $t1 $t2)}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def pp_skips_zeros [] {
|
||||
assert equal (pretty-print-duration {year:1, month:0, day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0 nanosecond:0}) "1yr "
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def pp_doesnt_skip_neg [] { # datetime-diff can't return negative units, but prettyprint shouldn't skip them (if passed handcrafted record)
|
||||
assert equal (pretty-print-duration {year:-1, month:0, day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0 nanosecond:0}) "-1yr "
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
# Test std/formats when importing module-only
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use std/formats *
|
||||
|
||||
@ -30,113 +31,113 @@ def test_data_multiline [--nuon] {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_multiple_objects [] {
|
||||
let result = test_data_multiline | from ndjson
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_single_object [] {
|
||||
let result = '{"a": 1}' | from ndjson
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_invalid_object [] {
|
||||
assert error { '{"a":1' | from ndjson }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_multiple_objects [] {
|
||||
let result = test_data_multiline | from jsonl
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_single_object [] {
|
||||
let result = '{"a": 1}' | from jsonl
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_invalid_object [] {
|
||||
assert error { '{"a":1' | from jsonl }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndjson_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to ndjson | str trim
|
||||
let expect = test_data_multiline
|
||||
assert equal $result $expect "could not convert to NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndjson_single_object [] {
|
||||
let result = [{a:1}] | to ndjson | str trim
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_jsonl_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to jsonl | str trim
|
||||
let expect = test_data_multiline
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_jsonl_single_object [] {
|
||||
let result = [{a:1}] | to jsonl | str trim
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_multiple_objects [] {
|
||||
let result = test_data_multiline | from ndnuon
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_single_object [] {
|
||||
let result = '{a: 1}' | from ndnuon
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from ndnuon }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to ndnuon | str trim
|
||||
let expect = test_data_multiline --nuon
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_single_object [] {
|
||||
let result = [{a:1}] | to ndnuon | str trim
|
||||
let expect = "{a: 1}"
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_multiline_strings [] {
|
||||
let result = "foo\n\\n\nbar" | to ndnuon
|
||||
let expect = '"foo\n\\n\nbar"'
|
||||
assert equal $result $expect "could not convert multiline string to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_multiline_strings [] {
|
||||
let result = '"foo\n\\n\nbar"' | from ndnuon
|
||||
let expect = ["foo\n\\n\nbar"]
|
||||
|
@ -1,13 +1,14 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
use std/help
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def show_help_on_commands [] {
|
||||
let help_result = (help alias)
|
||||
assert ("item not found" not-in $help_result)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def show_help_on_error_make [] {
|
||||
let help_result = (help error make)
|
||||
assert ("Error: nu::shell::eval_block_with_input" not-in $help_result)
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std/testing *
|
||||
use std *
|
||||
use std/assert
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_find [] {
|
||||
let hastack1 = [1 2 3 4 5 6 7]
|
||||
let hastack2 = [nushell rust shell iter std]
|
||||
@ -20,7 +21,7 @@ def iter_find [] {
|
||||
assert equal $res null
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_intersperse [] {
|
||||
let res = ([1 2 3 4] | iter intersperse 0)
|
||||
assert equal $res [1 0 2 0 3 0 4]
|
||||
@ -41,7 +42,7 @@ def iter_intersperse [] {
|
||||
assert equal $res [4]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_scan [] {
|
||||
let scanned = ([1 2 3] | iter scan 0 {|x, y| $x + $y} -n)
|
||||
assert equal $scanned [1, 3, 6]
|
||||
@ -56,7 +57,7 @@ def iter_scan [] {
|
||||
assert equal $scanned ["a" "ab" "abc" "abcd"]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_filter_map [] {
|
||||
let res = ([2 5 "4" 7] | iter filter-map {|it| $it ** 2})
|
||||
assert equal $res [4 25 49]
|
||||
@ -68,7 +69,7 @@ def iter_filter_map [] {
|
||||
assert equal $res [3 42 69]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_find_index [] {
|
||||
let res = (
|
||||
["iter", "abc", "shell", "around", "nushell", "std"]
|
||||
@ -84,7 +85,7 @@ def iter_find_index [] {
|
||||
assert equal $res 0
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_zip_with [] {
|
||||
let res = (
|
||||
[1 2 3] | iter zip-with [2 3 4] {|a, b| $a + $b }
|
||||
@ -111,7 +112,7 @@ def iter_zip_with [] {
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_flat_map [] {
|
||||
let res = (
|
||||
[[1 2 3] [2 3 4] [5 6 7]] | iter flat-map {|it| $it | math sum}
|
||||
@ -122,7 +123,7 @@ def iter_flat_map [] {
|
||||
assert equal $res [11 22 33]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def iter_zip_into_record [] {
|
||||
let headers = [name repo position]
|
||||
let values = [rust github 1]
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def banner [] {
|
||||
use std/prelude
|
||||
assert ((prelude banner | lines | length) == 16)
|
||||
|
@ -1,28 +1,29 @@
|
||||
use std/testing *
|
||||
use std/log
|
||||
use std/assert
|
||||
|
||||
#[before-each]
|
||||
@before-each
|
||||
def before-each [] {
|
||||
log debug "Setup is running"
|
||||
{msg: "This is the context"}
|
||||
}
|
||||
|
||||
#[after-each]
|
||||
@after-each
|
||||
def after-each [] {
|
||||
log debug $"Teardown is running. Context: ($in)"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def assert_pass [] {
|
||||
log debug $"Assert is running. Context: ($in)"
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@ignore
|
||||
def assert_skip [] {
|
||||
log debug $"Assert is running. Context: ($in)"
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@ignore
|
||||
def assert_fail_skipped_by_default [] {
|
||||
# Change test-skip to test if you want to see what happens if a test fails
|
||||
log debug $"Assert is running. Context: ($in)"
|
||||
|
@ -1,4 +1,5 @@
|
||||
# Test std/formats when importing `use std *`
|
||||
use std/testing *
|
||||
use std *
|
||||
|
||||
def test_data_multiline [--nuon] {
|
||||
@ -30,113 +31,113 @@ def test_data_multiline [--nuon] {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_multiple_objects [] {
|
||||
let result = test_data_multiline | formats from ndjson
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_single_object [] {
|
||||
let result = '{"a": 1}' | formats from ndjson
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndjson_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from ndjson }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_multiple_objects [] {
|
||||
let result = test_data_multiline | formats from jsonl
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_single_object [] {
|
||||
let result = '{"a": 1}' | formats from jsonl
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_jsonl_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from jsonl }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndjson_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to ndjson | str trim
|
||||
let expect = test_data_multiline
|
||||
assert equal $result $expect "could not convert to NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndjson_single_object [] {
|
||||
let result = [{a:1}] | formats to ndjson | str trim
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to NDJSON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_jsonl_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to jsonl | str trim
|
||||
let expect = test_data_multiline
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_jsonl_single_object [] {
|
||||
let result = [{a:1}] | formats to jsonl | str trim
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_multiple_objects [] {
|
||||
let result = test_data_multiline | formats from ndnuon
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_single_object [] {
|
||||
let result = '{a: 1}' | formats from ndnuon
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from ndnuon }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_multiple_objects [] {
|
||||
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to ndnuon | str trim
|
||||
let expect = test_data_multiline --nuon
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_single_object [] {
|
||||
let result = [{a:1}] | formats to ndnuon | str trim
|
||||
let expect = "{a: 1}"
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def to_ndnuon_multiline_strings [] {
|
||||
let result = "foo\n\\n\nbar" | formats to ndnuon
|
||||
let expect = '"foo\n\\n\nbar"'
|
||||
assert equal $result $expect "could not convert multiline string to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def from_ndnuon_multiline_strings [] {
|
||||
let result = '"foo\n\\n\nbar"' | formats from ndnuon
|
||||
let expect = ["foo\n\\n\nbar"]
|
||||
|
@ -1,11 +1,12 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
export use std *
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def std_post_import [] {
|
||||
assert length (scope commands | where name == "path add") 1
|
||||
assert length (scope commands | where name == "ellie") 1
|
||||
assert length (scope commands | where name == "repeat") 1
|
||||
assert length (scope commands | where name == "formats from jsonl") 1
|
||||
assert length (scope commands | where name == "dt datetime-diff") 1
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std/testing *
|
||||
use std/assert
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def std_pre_import [] {
|
||||
# These commands shouldn't exist without an import
|
||||
assert length (scope commands | where name == "path add") 0
|
||||
@ -8,4 +9,4 @@ def std_pre_import [] {
|
||||
assert length (scope commands | where name == "repeat") 0
|
||||
assert length (scope commands | where name == "from jsonl") 0
|
||||
assert length (scope commands | where name == "datetime-diff") 0
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std/testing *
|
||||
use std *
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def path_add [] {
|
||||
use std/assert
|
||||
|
||||
@ -44,7 +45,7 @@ def path_add [] {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def path_add_expand [] {
|
||||
use std/assert
|
||||
|
||||
@ -70,7 +71,7 @@ def path_add_expand [] {
|
||||
rm $real_dir $link_dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def repeat_things [] {
|
||||
use std/assert
|
||||
assert error { "foo" | repeat -1 }
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std/testing *
|
||||
use std/util *
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def path_add [] {
|
||||
use std/assert
|
||||
|
||||
@ -44,7 +45,7 @@ def path_add [] {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def path_add_expand [] {
|
||||
use std/assert
|
||||
|
||||
@ -70,7 +71,7 @@ def path_add_expand [] {
|
||||
rm $real_dir $link_dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def repeat_things [] {
|
||||
use std/assert
|
||||
assert error { "foo" | repeat -1 }
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std/testing *
|
||||
use std/xml *
|
||||
use std/assert
|
||||
|
||||
#[before-each]
|
||||
@before-each
|
||||
def before-each [] {
|
||||
{sample_xml: ('
|
||||
<a>
|
||||
@ -17,7 +18,7 @@ def before-each [] {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def xml_xaccess [] {
|
||||
let sample_xml = $in.sample_xml
|
||||
|
||||
@ -28,7 +29,7 @@ def xml_xaccess [] {
|
||||
assert equal ($sample_xml | xaccess [* * * {|e| $e.attributes != {}}]) [[tag, attributes, content]; [c, {a: b}, []]]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def xml_xupdate [] {
|
||||
let sample_xml = $in.sample_xml
|
||||
|
||||
@ -37,7 +38,7 @@ def xml_xupdate [] {
|
||||
assert equal ($sample_xml | xupdate [* * * {|e| $e.attributes != {}}] {|x| $x | update content ['xml']}) {tag: a, attributes: {}, content: [[tag, attributes, content]; [b, {}, [[tag, attributes, content]; [c, {a: b}, [xml]]]], [c, {}, []], [d, {}, [[tag, attributes, content]; [e, {}, [[tag, attributes, content]; [null, null, z]]], [e, {}, [[tag, attributes, content]; [null, null, x]]]]]]}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@test
|
||||
def xml_xinsert [] {
|
||||
let sample_xml = $in.sample_xml
|
||||
|
||||
|
Reference in New Issue
Block a user