|
| 1 | +use std/testing * |
| 2 | +use std/assert |
| 3 | + |
| 4 | +@test |
| 5 | +def "test example" [] { |
| 6 | + assert str contains (example) "Example commands for Nushell plugins" |
| 7 | +} |
| 8 | + |
| 9 | +@test |
| 10 | +def "test example call-decl" [] { |
| 11 | + let expected = version | columns | length |
| 12 | + assert length (example call-decl version | columns) $expected |
| 13 | +} |
| 14 | + |
| 15 | +@test |
| 16 | +def "test example collect-bytes" [] { |
| 17 | + let expected = "ab" |
| 18 | + assert equal ([a, b] | example collect-bytes) $expected |
| 19 | +} |
| 20 | + |
| 21 | +@test |
| 22 | +def "test example config" [] { |
| 23 | + let config = {a: 1, b: "b"} |
| 24 | + $env.config.plugins.example = $config |
| 25 | + assert equal (example config) $config |
| 26 | +} |
| 27 | + |
| 28 | +@test |
| 29 | +@ignore |
| 30 | +def "test example ctrlc" [] { |
| 31 | + # TODO: test this |
| 32 | +} |
| 33 | + |
| 34 | +@test |
| 35 | +@ignore |
| 36 | +def "test example disable-gc" [] { |
| 37 | + # TODO: test this |
| 38 | +} |
| 39 | + |
| 40 | +@test |
| 41 | +def "test example echo" [] { |
| 42 | + let expected = seq 1 5 | collect |
| 43 | + assert equal (seq 1 5 | example echo) $expected |
| 44 | +} |
| 45 | + |
| 46 | +@test |
| 47 | +def "test example env" [] { |
| 48 | + let value = "🐘" |
| 49 | + $env.ELLY = $value |
| 50 | + assert equal (example env | get ELLY) $value |
| 51 | +} |
| 52 | + |
| 53 | +@test |
| 54 | +@ignore |
| 55 | +def "test example for-each" [] { |
| 56 | + # TODO: test this |
| 57 | +} |
| 58 | + |
| 59 | +@test |
| 60 | +def "test example generate" [] { |
| 61 | + let expected = [0, 2, 4, 6, 8, 10] |
| 62 | + let closure = {|i| if $i <= 10 {{out: $i, next: ($i + 2)}}} |
| 63 | + let actual = example generate 0 $closure |
| 64 | + assert equal $actual $expected |
| 65 | +} |
| 66 | + |
| 67 | +@test |
| 68 | +def "test example one" [] { |
| 69 | + # TODO: test the actual behavior |
| 70 | + assert equal (example one 1 a) null |
| 71 | +} |
| 72 | + |
| 73 | +@test |
| 74 | +def "test example seq" [] { |
| 75 | + assert equal (example seq 1 5) (seq 1 5) |
| 76 | +} |
| 77 | + |
| 78 | +@test |
| 79 | +def "test example sum" [] { |
| 80 | + let input = [1, 2, 3] |
| 81 | + let expected = $input | math sum |
| 82 | + let actual = $input | example sum |
| 83 | + assert equal $expected $actual |
| 84 | +} |
| 85 | + |
| 86 | +@test |
| 87 | +def "test example three" [] { |
| 88 | + assert error {|| example three 1 a} |
| 89 | +} |
| 90 | + |
| 91 | +@test |
| 92 | +def "test example two" [] { |
| 93 | + let expected = (0..9 | generate {|i| {out: {one: $i, two: ($i * 2), three: ($i * 3)}, next: ($i + 1)}} 0) |
| 94 | + assert equal (example two 1 a) $expected |
| 95 | +} |
| 96 | + |
| 97 | +@test |
| 98 | +def "test example view span" [] { |
| 99 | + let expected = "'hello ' ++ 'world'" |
| 100 | + let actual = ('hello ' ++ 'world') | example view span |
| 101 | + assert equal $expected $actual |
| 102 | +} |
0 commit comments