Skip to content

Commit

Permalink
pkg: add some tests that pick defaults in builtins
Browse files Browse the repository at this point in the history
These tests should not change with an upcoming
CL that to support pkg.Schema.

Issue #2471

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ic941ea65432dfdd23743692c1e1efefc8de9da95
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199623
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Dispatch-Trailer: {"type":"trybot","CL":1199623,"patchset":4,"ref":"refs/changes/23/1199623/4","targetBranch":"master"}
  • Loading branch information
mpvl authored and cueckoo committed Sep 6, 2024
1 parent 5a77ce1 commit 3a8cacb
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cue/interpreter/wasm/testdata/cue/default.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Check that default values are resolved correctly.

exec cue eval -E --out cue
cmp stdout out/wasm

-- a.cue --
@extern("wasm")
package p

add: _ @extern("basic.wasm", abi=c, sig="func(int64, int64): int64")

x0: add(*1 | string, *2 | string)
-- basic.wasm --
-- out/wasm --
add: add
x0: 3
59 changes: 59 additions & 0 deletions cue/testdata/builtins/default.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- in.cue --
import (
"list"
"strings"
"text/template"
)

Len: len(*[1, 2, 3] | 0)
Close: close(*{} | 0)
And: and(*[1, 1] | int)
Or: or(*[1, 1] | int)
Div: div(*5 | string, 2)
Mod: mod(*5 | string, 2)
Quo: quo(*5 | string, 2)
Rem: rem(*5 | string, 2)
-- out/compile --
--- in.cue
{
Len: len((*[
1,
2,
3,
]|0))
Close: close((*{}|0))
And: and((*[
1,
1,
]|int))
Or: or((*[
1,
1,
]|int))
Div: div((*5|string), 2)
Mod: mod((*5|string), 2)
Quo: quo((*5|string), 2)
Rem: rem((*5|string), 2)
}
-- out/eval/stats --
Leaks: 0
Freed: 45
Reused: 40
Allocs: 5
Retain: 0

Unifications: 25
Conjuncts: 52
Disjuncts: 45
-- out/eval --
(struct){
Len: (int){ 3 }
Close: (struct){
}
And: (int){ 1 }
Or: (int){ 1 }
Div: (int){ 2 }
Mod: (int){ 1 }
Quo: (int){ 2 }
Rem: (int){ 1 }
}
21 changes: 21 additions & 0 deletions pkg/net/testdata/toip4.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- in.cue --
import "net"

fail: {
t1: net.ToIP4(1 | 2)
t2: net.ToIP4(string)
}

ok: {
t1: net.ToIP4(*"4.4.4.4" | "8.8.8.8")
}
-- out/net --
import "net"

fail: {
t1: net.ToIP4(1 | 2)
t2: net.ToIP4(string)
}
ok: {
t1: [4, 4, 4, 4]
}
6 changes: 6 additions & 0 deletions pkg/strings/testdata/join.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- in.cue --
import "strings"

disjunctDefault: strings.Join(*["Hello", "World!"] | int, " ")
-- out/strings --
disjunctDefault: "Hello World!"

0 comments on commit 3a8cacb

Please sign in to comment.