Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port before_v0.60/config_management before_v0.60/language before_v0.60/prompt before_v0.60/tests #851

Merged
Prev Previous commit
Next Next commit
port language module: playground/lib.nu and std/date.nu
`playground/lib.nu`
- `str collect` -> `str join`
- `$nu.env | default ...` -> `$env | get -i ... | default`
- `$false` -> `false`
- `block` -> `closure`
- explicit print
- `if {} {}` -> `if {} else {}`
- `each {} | all?` -> all {}
- remove strange missing `$title`, add `$topic` argument
- add `any` -> `list<any>`
- move `length == length` first, then `zip`
- `zip | pivot` -> `zip`

`std/date.nu`
- `date format` -> `format date`
  • Loading branch information
39555 committed May 26, 2024
commit b61ad9e47693731519cec67bd3e6120d72a05a4c
65 changes: 32 additions & 33 deletions modules/language/playground/lib.nu
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
def playground [topic, block] {
with-env [N 5 REJECT slow] {
echo $topic " tests" (char newline) | str collect
def playground [topic, closure] {
with-env {N: 5 REJECT: slow } {
print (echo $topic " tests" (char newline) | str join)

do $block
do $closure
}
}

def scene [
topic: any
--tag: string
block: block
closure: closure
] {
$" ($topic)(char newline)"
do $block
print $" ($topic)(char newline)"
do $closure
}

def play [
topic: any
--tag: string
block: block
closure: closure
] {
let title = $topic;

let is_tag_empty = ($tag | empty?);
let should_run_all = ($nu.env | default RUN_ALL $false | get RUN_ALL);
let is_tag_empty = ($tag | is-empty);
let should_run_all = ($env | get -i RUN_ALL | default false);

if $is_tag_empty {
do $block
} {
if $tag == $nu.env.REJECT and $should_run_all {
$" ($topic) ... (ansi yellow)skipped(ansi reset) (char newline)"
} { do $block }
do $closure $topic
} else {
if $tag == $env.REJECT and $should_run_all {
$" ($topic) ... (ansi yellow)skipped(ansi reset) (char newline)"
} else {
do $closure $topic
}
}
}

def expect [
actual: any
--to-be: any
topic: string
actual: list<any>
--to-be: list<any>
] {
let are_equal = ($actual | zip { $to-be } | pivot header_names values | each {|case|
let values = $case.values;

$values.0 == $values.1
let are_equal = (($actual | length) == ($to_be | length)) and ($actual | zip $to_be | all {|case|
$case.0 == $case.1
}
| all? $it) and (($actual | get | length) == ($to-be | get | length));

let line = (if $true == $are_equal {
$"(ansi green)ok(ansi reset)(char newline)"
} {
$"(ansi red)failed(ansi reset)(char newline)"
});

$" ($title) ... ($line)"
}
)

let line = (if true == $are_equal {
$"(ansi green)ok(ansi reset)(char newline)"
} else {
$"(ansi red)failed(ansi reset)(char newline)"
}
)
$" ($topic) ... ($line)"
}
2 changes: 1 addition & 1 deletion modules/language/std/date.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ def "date local" [now] {
insert time {|value|
let converted = ($now | date to-timezone $value.tz);

$converted | date format '%c'
$converted | format date '%c'
}
}