Last active
October 17, 2019 23:57
-
-
Save rudolph9/eccc978e71fd9c32b0ae182ce6854c16 to your computer and use it in GitHub Desktop.
Cuelang rspec like testing package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cue eval ttest.cue | |
FooBar: string | |
test: { | |
subject: _ | |
describe: { | |
"One big definition": { | |
subject: string | |
it: { | |
"should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
describe: { | |
NESTED: { | |
subject: string | |
it: { | |
"NESTED should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"NESTED should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"NESTED should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
} | |
NESTED1: { | |
subject: string | |
it: { | |
"NESTED1 subject should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"NESTED1 subject should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"NESTED1 subject should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
test1: { | |
subject: _ | |
describe: { | |
"Lots of small definitions with shared field path": { | |
subject: string | |
it: { | |
"should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
describe: { | |
NESTED: { | |
subject: string | |
it: { | |
"NESTED should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"NESTED should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"NESTED should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
} | |
NESTED1: { | |
subject: string | |
it: { | |
"NESTED1 should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"NESTED1 should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"NESTED1 should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
test2: { | |
subject: _ | |
describe: { | |
"shared tests": { | |
subject: string | |
it: { | |
"should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
describe: { | |
Nested: { | |
subject: string | |
it: { | |
"Nested should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"Nested should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"Nested should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
_extraInfo: "Nested " | |
} | |
} | |
_extraInfo: "" | |
} | |
} | |
} | |
test3: { | |
subject: _ | |
describe: { | |
"0": { | |
describe: { | |
"1": { | |
describe: { | |
"2": { | |
describe: { | |
"3": { | |
describe: { | |
"4": { | |
describe: { | |
"5": { | |
describe: { | |
"6": { | |
describe: { | |
"7": { | |
subject: string | |
it: { | |
"max nesting depth should work for invalid": { | |
assert: { | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
"max nesting depth should work for valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
} | |
} | |
"max nesting depth should allow both invalid and valid": { | |
assert: { | |
valid: { | |
value: "foo" | |
pass: true | |
} | |
invalid: { | |
value: 5 | |
pass: true | |
} | |
} | |
} | |
} | |
_extraInfo: "max nesting depth " | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package t | |
Describe: { | |
<_>: { | |
describe?: Describe | |
subject?: _ | |
it?: { | |
<_> : close({ | |
assert valid?: { | |
value: _ | |
testsResult = value & subject | |
pass: ( *testsResult | _|_ ) != _|_ | |
if pass == false { | |
error: null & "The value of assert should NOT have resulted in an error" | |
pass: true | |
} | |
} | |
assert invalid?: { | |
value: _ | |
testsResult = value & subject | |
pass: ( *testsResult | _|_ ) == _|_ | |
if pass == false { | |
error: null & "The value of assert should NOT have resulted in an error" | |
pass: true | |
} | |
} | |
}) | |
} | |
} | |
} | |
Test: { | |
subject: _ | |
describe: { | |
Describe | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ttest | |
import "xr.gy/t" | |
FooBar: string | |
test: t.Test & { | |
describe "One big definition": { | |
subject: FooBar | |
it "should work for invalid": { | |
assert invalid: {value: 5} | |
} | |
it "should work for valid": { | |
assert valid: {value: "foo"} | |
} | |
it "should allow both invalid and valid": { | |
assert valid: {value: "foo"} | |
assert invalid: {value: 5} | |
} | |
describe "NESTED": { | |
subject: FooBar | |
it "NESTED should work for invalid": { | |
assert invalid: {value: 5} | |
} | |
it "NESTED should work for valid": { | |
assert valid: {value: "foo"} | |
} | |
it "NESTED should allow both invalid and valid": { | |
assert valid: {value: "foo"} | |
assert invalid: {value: 5} | |
} | |
} | |
parent_subject = subject | |
describe "NESTED1": { | |
subject: parent_subject | |
it "NESTED1 subject should work for invalid": { | |
assert invalid: {value: 5} | |
} | |
it "NESTED1 subject should work for valid": { | |
assert valid: {value: "foo"} | |
} | |
it "NESTED1 subject should allow both invalid and valid": { | |
assert valid: {value: "foo"} | |
assert invalid: {value: 5} | |
} | |
} | |
} | |
} | |
test1: t.Test | |
test1 describe "Lots of small definitions with shared field path" subject: FooBar | |
test1 describe "Lots of small definitions with shared field path" it "should work for invalid" assert invalid value: 5 | |
test1 describe "Lots of small definitions with shared field path" it "should work for valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" it "should allow both invalid and valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" it "should allow both invalid and valid" assert invalid value: 5 | |
test1: t.Test | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED" subject: FooBar | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED" it "NESTED should work for invalid" assert invalid value: 5 | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED" it "NESTED should work for valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED" it "NESTED should allow both invalid and valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED" it "NESTED should allow both invalid and valid" assert invalid value: 5 | |
test1: t.Test | |
test1 describe "Lots of small definitions with shared field path": { | |
//parent_subject = test1.describe["Lots of small definitions with shared field path"].subject | |
subject?: _ | |
parent_subject = subject | |
describe "NESTED1" subject: parent_subject | |
} | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED1" it "NESTED1 should work for invalid" assert invalid value: 5 | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED1" it "NESTED1 should work for valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED1" it "NESTED1 should allow both invalid and valid" assert valid value: "foo" | |
test1 describe "Lots of small definitions with shared field path" describe "NESTED1" it "NESTED1 should allow both invalid and valid" assert invalid value: 5 | |
sharedTests = { | |
_extraInfo: *"" | string | |
subject: FooBar | |
it "\(_extraInfo)should work for invalid": { | |
assert invalid: {value: 5} | |
} | |
it "\(_extraInfo)should work for valid": { | |
assert valid: {value: "foo"} | |
} | |
it "\(_extraInfo)should allow both invalid and valid": { | |
assert valid: {value: "foo"} | |
assert invalid: {value: 5} | |
} | |
} | |
test2: t.Test | |
test2 describe "shared tests": sharedTests | |
test2 describe "shared tests" describe "Nested": sharedTests & {_extraInfo: "Nested "} | |
test3: t.Test | |
test3 describe "0" describe "1" describe "2" describe "3" describe "4" describe "5" describe "6" describe "7": sharedTests & {_extraInfo: "max nesting depth "} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment