Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/fibonacci-recursive.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This is a much less efficient, recursive version of fibonacci that can be used to test our
# command call performance.

use std bench
use std/bench

def fib [n: int] {
match $n {
Expand All @@ -13,5 +13,5 @@ def fib [n: int] {
}

def main [] {
print (bench { 0..20 | each { |n| fib $n } } | reject times)
print (bench { 0..20 | each { |n| fib $n } })
}
4 changes: 2 additions & 2 deletions benchmarks/fibonacci.nu
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Originally added by @devyn to show what absolute best case performance for IR evaluation can look
# like. Not super representative of normal Nushell code.

use std bench
use std/bench

def fib [n: int] {
mut a = 0
Expand All @@ -20,5 +20,5 @@ def fib [n: int] {
}

def main [] {
print (bench -n 1000 { 0..50 | each { |n| fib $n } } | reject times)
print (bench -n 1000 { 0..50 | each { |n| fib $n } })
}
2 changes: 1 addition & 1 deletion benchmarks/random-bytes.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std bench
use std/bench

def "random bytes" [n: int]: nothing -> binary {
seq 1 ($n / 8 + 1)
Expand Down
2 changes: 1 addition & 1 deletion modules/fun/star.nu
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
# }


use std math
use std/math

def atan2 [y x] {
if $x > 0 {
Expand Down
8 changes: 4 additions & 4 deletions modules/maths/math_functions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ export def scale-minmax-table [a, b,input?] {
# ```
export def "cartesian product" [
...iters: list<any> # the iterables you want the cartesian product of
]: nothing -> list<list<any>> {
def aux [a: list<list<any>>]: nothing -> list<list<any>> {
]: nothing -> list<any> {
def aux [a: list<list<any>>]: nothing -> list<any> {
if ($a | is-empty) {
return []
}
Expand All @@ -215,7 +215,7 @@ export def "cartesian product" [

#[test]
def cartesian_product [] {
use std assert
use std/assert

# emptiness
assert equal (cartesian product [] []) []
Expand Down Expand Up @@ -277,7 +277,7 @@ export def ways-to-add-up-to [n: int]: [ nothing -> list<list<int>> ] {

#[test]
def test [] {
use std assert
use std/assert
for it in [
[n, expected];

Expand Down
7 changes: 5 additions & 2 deletions modules/prompt/full-line.nu
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
#
# credit panache-git for the git status widget.

use std dirs
use std assert
use std/dirs
use std/assert

# set up `$env.DIRS_LIST` for whoever imports this module, since `dirs` reads it
export-env { use std/dirs [] }

# build the prompt from segments, looks like:
#
Expand Down
5 changes: 3 additions & 2 deletions sourced/progress_bar/bar.nu
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def 'bar' [
--width (-w): int = 5
] {
let blocks = [null "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"]
let $whole_part = (($blocks | last) * ($percentage * $width // 1))
let $whole_part = ("" | fill --character ($blocks | last) --width ($percentage * $width // 1 | into int))
let $fraction = (
$blocks
| get (
($percentage * $width) mod 1
| $in * ($blocks | length | $in - 1)
| math round
| into int
)
)

Expand All @@ -36,7 +37,7 @@ def 'bar' [
}
}

use std assert equal
use std/assert equal

#[test]
def bar_tests [] {
Expand Down
34 changes: 15 additions & 19 deletions sourced/typeof.nu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def typeof [] {

#[test]
def simple_type [] {
use std assert
use std/assert

assert equal ("foo" | typeof) "string"
assert equal (123 | typeof) "int"
Expand All @@ -37,56 +37,52 @@ def simple_type [] {

#[test]
def list_type [] {
use std assert
use std/assert

assert equal ([1 2 3] | typeof) {type: "list", items: "int"}
assert equal (["foo" "bar" "baz"] | typeof) {type: "list", items: "string"}
assert equal (["foo" 2 true] | typeof) {type: "list", items: "any"}
assert equal (["foo" 2 true] | typeof) {type: "list", items: "oneof<string, int, bool>"}
}

#[test]
def table_type [] {
use std assert
use std/assert
assert equal (ls | typeof) {
type: "table",
columns: {
name: "string",
type: "string",
size: "filesize",
modified: "date",
modified: "datetime",
}
}
}


#[test]
def record_type [] {
use std assert
assert equal ($nu | typeof) {
use std/assert
let data = {
name: "foo",
pid: 123,
os-info: {arch: "x86_64", kernel_version: "6.1"},
startup-time: 2sec,
is-login: false,
}
assert equal ($data | typeof) {
type: "record",
fields: {
default-config-dir: "string",
config-path: "string",
env-path: "string",
history-path: "string",
loginshell-path: "string",
plugin-path: "string",
home-path: "string",
temp-path: "string",
name: "string",
pid: "int",
os-info: {
type: "record",
fields: {
name: "string",
arch: "string",
family: "string",
kernel_version: "string",
}
},
startup-time: "duration",
is-interactive: "bool",
is-login: "bool",
current-exe: "string",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ export use bulk-rename.nu *
export use set-env.nu *
export use bench.nu
export use script-parsing.nu [ parse-arg ]
export use conversions *
export use tables *
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export def --env main [
--append (-a) # Append to the previous value or wrap in a new list
]: nothing -> nothing {
def 'get or' [default field] {
get --ignore-errors $field | default $default
get --optional $field | default $default
}
let value = if $append {
$env | get or [] $field | append $value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc bench

export def "test bench-timings" [] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc 'bulk-rename'

const fixture = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc/math

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc record

export def "test list_merge" [] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc parse-arg

const SPAN = { start: 0, end: 0 }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc str

export def "test str dedent" [] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc str

export def "test append" [] {
Expand Down
2 changes: 1 addition & 1 deletion stdlib-candidate-archive/tests/conversions.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc/conversions *

#[test]
Expand Down
Loading