1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

Merge pull request #93 from andrasio/infra

Infraestructure initial setup.
This commit is contained in:
Andrés N. Robalino 2021-08-29 15:10:11 -05:00 committed by GitHub
commit 130cb37d2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 142 additions and 18 deletions

12
assets/core_team.nu Normal file
View file

@ -0,0 +1,12 @@
def "nu core-team" [] {
[
[ 'name', 'tz'];
[ 'andres', 'America/Guayaquil']
[ 'fdncred', 'US/Central']
[ 'gedge', 'US/Eastern']
[ 'jt', 'NZ']
[ 'wycats', 'US/Pacific']
[ 'kubouch', 'Europe/Helsinki']
['elferherrera', 'Europe/London']
]
}

View file

@ -0,0 +1,25 @@
source lib/scripts.nu
source assets/core_team.nu
let next_call = ("2021-08-31 15:00:21.290597200 -05:00" | str to-datetime);
let people = (nu core-team | date local $next_call);
def say [block] {
each {|person|
do $block (
$person | merge {
[[name]; [($person.name | str capitalize)]]
}
)
} | str collect (char newline)
}
$people | say {|person| $"($person.name)'s timezone is ($person.tz)"}
$"
for the next call happening on ($next_call | date format '%c').. in their timezones they would be:
"
$people | say {|person| $"($person.name)'s: ($person.time)"}

1
language/playground.nu Normal file
View file

@ -0,0 +1 @@
source language/playground/lib.nu

View file

@ -0,0 +1,55 @@
def playground [topic, block] {
with-env [N 5 REJECT slow] {
echo $topic " tests" (char newline) | str collect
do $block
}
}
def scene [
topic: any
--tag: string
block: block
] {
$" ($topic)(char newline)"
do $block
}
def play [
topic: any
--tag: string
block: block
] {
let title = $topic;
let is_tag_empty = ($tag | empty?);
let should_run_all = ($nu.env | default RUN_ALL $false | get RUN_ALL);
if $is_tag_empty {
do $block
} {
if $tag == $nu.env.REJECT && $should_run_all {
$" ($topic) ... (ansi yellow)skipped(ansi reset) (char newline)"
} { do $block }
}
}
def expect [
actual: any
--to-be: any
] {
let are_equal = ($actual | zip { $to-be } | pivot header_names values | each {|case|
let values = $case.values;
$values.0 == $values.1
}
| all? $it) && (($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)"
}

1
language/std.nu Normal file
View file

@ -0,0 +1 @@
source language/std/date.nu

7
language/std/date.nu Normal file
View file

@ -0,0 +1,7 @@
def "date local" [now] {
insert time {|value|
let converted = ($now | date to-timezone $value.tz);
$converted | date format '%c'
}
}

1
lib/scripts.nu Normal file
View file

@ -0,0 +1 @@
source language/std.nu

View file

@ -1,18 +0,0 @@
let m_table = (
[
['name', 'tz', 'time'];
['andres' 'America/Guayaquil' ' ']
['fdncred' 'US/Central' ' ']
['gedge' 'US/Eastern' ' ']
['jt' 'NZ' ' ']
['wycats' 'US/Pacific' ' ']
['kubouch' 'Europe/Helsinki' ' ']
['elferherrera' 'Europe/London' ' ']
]
)
let now = (date now)
$m_table | update time {
each { |name|
$now | date to-timezone ($name | get tz) | date format '%c'
}
}

View file

@ -0,0 +1,38 @@
source lib/scripts.nu
def mock-now [] {
"2021-08-29 03:31:21.290597200 -05:00" | str to-datetime
}
def people [] {
[
[ 'name', 'tz'];
[ 'andres', 'America/Guayaquil']
[ 'fdncred', 'US/Central']
]
}
playground "std/date" {
scene 'command: "date local"' {
play "adds times in local timezone" {
let expected_times = [
[time];
["Sun Aug 29 03:31:21 2021"]
["Sun Aug 29 03:31:21 2021"]
];
let actual = (people |
date local (mock-now) |
select time
);
expect $actual --to-be $expected_times
}
}
}

2
tests/main.nu Normal file
View file

@ -0,0 +1,2 @@
source language/playground.nu
source tests/language/std/date.nu