forked from extern/nushell
2ccbefe01e
# Description
we've discussed a bit about the location of the standard library in the
#standard-library channel of the discord server => **the previous
location, `crates/nu-utils/src/sample_config/`, was a bit confusing**
- is `std.nu` a config file, just as `default_config.nu` or
`default_env.nu`?
- what is this `tests.nu` file inside the `sample_config/`?
in this PR, i propose moving the standard library to
`crates/nu-utils/standard_library/` for a few reasons:
- `std.nu` is not a config file, so it should not be next to config
files in a `sample_config/` directory
- `tests.nu` is confusing if mixed with other unrelated files
- `crates/nu-utils/` appears to be a good place for the standard library
as it is meant to be a tool for `nushell`
- i thought it would be strange to have `std.nu` inside
`crates/nu-utils/src/` as this directory is generally filled with `rust`
files, right?
these are the reasons why i choose to propose
`crates/nu-utils/standard_library/` 😋
# User-Facing Changes
the standard library is now used with
```bash
use crates/nu-utils/standard_library/std.nu
```
and the tests are run with
```bash
nu crates/nu-utils/standard_library/tests.nu
```
# Tests + Formatting
```bash
$nothing
```
# After Submitting
```bash
$nothing
```
47 lines
1.0 KiB
Plaintext
47 lines
1.0 KiB
Plaintext
use std.nu
|
|
|
|
def test_assert [] {
|
|
def test_failing [code: closure] {
|
|
let code_did_run = (try { do $code; true } catch { false })
|
|
|
|
if $code_did_run {
|
|
error make {msg: (view source $code)}
|
|
}
|
|
}
|
|
|
|
std assert true
|
|
std assert (1 + 2 == 3)
|
|
test_failing { std assert false }
|
|
test_failing { std assert (1 + 2 == 4) }
|
|
|
|
std assert eq (1 + 2) 3
|
|
test_failing { std assert eq 1 "foo" }
|
|
test_failing { std assert eq (1 + 2) 4) }
|
|
|
|
std assert ne (1 + 2) 4
|
|
test_failing { std assert ne 1 "foo" }
|
|
test_failing { std assert ne (1 + 2) 3) }
|
|
}
|
|
|
|
def tests [] {
|
|
use std.nu assert
|
|
|
|
let branches = {
|
|
1: { -1 }
|
|
2: { -2 }
|
|
}
|
|
|
|
assert ((std match 1 $branches) == -1)
|
|
assert ((std match 2 $branches) == -2)
|
|
assert ((std match 3 $branches) == $nothing)
|
|
|
|
assert ((std match 1 $branches { 0 }) == -1)
|
|
assert ((std match 2 $branches { 0 }) == -2)
|
|
assert ((std match 3 $branches { 0 }) == 0)
|
|
}
|
|
|
|
def main [] {
|
|
test_assert
|
|
tests
|
|
}
|