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

Add snap tests for sentinel language #139

Merged
merged 1 commit into from
Aug 1, 2024
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
43 changes: 43 additions & 0 deletions tests/snapshot/sentinel/boolean_expr.sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# https://developer.hashicorp.com/sentinel/docs/language/boolexpr

value = (p and q) or r
value = p and (q or r)

value = 42 == -1
value = 42 != -1
value = 42 < -1
value = 42 <= -1
value = 42 > -1
value = 42 >= -1

# Sets
value = [1, 2, 3] contains 2
value = [1, 2, 3] contains 5
value = [1, 2, 3] contains "value"
value = [1, 2, 3] not contains "value"

value = { "a": 1, "b": 2 } contains "a"
value = { "a": 1, "b": 2 } contains "c"
value = { "a": 1, "b": 2 } contains 2
value = { "a": 1, "b": 2 } not contains 2

# Matches
value = "test" matches "e"
value = "test" matches "^e"
value = "TEST" matches "test"
value = "TEST" matches "(?i)test"
value = "ABC123" matches "[A-Z]+\\d+"
value = "test" not matches "e"

# Any, All
all group.tasks as t { t.driver is "vmware" }
any group.tasks as t { t.driver is "vmware" }

any ["a", "b"] as char { char is "a" } or other_value is "another"

# Emptiness/Defined
value = x is empty
value = x is not empty

value = x is defined
value = x is not defined
398 changes: 398 additions & 0 deletions tests/snapshot/sentinel/boolean_expr.sentinel.snap

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions tests/snapshot/sentinel/collections.sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://developer.hashicorp.com/sentinel/docs/language/collection-operations

# filter
filter list as value { condition } // Single-iterator, list
filter list as idx, value { condition } // Double-iterator, list

filter map as key { condition } // Single-iterator, map
filter map as key, value { condition } // Double-iterator, map

# map
l = [1, 2]
r = map l as v { v % 2 } // [false, true]

m = { "a": "foo", "b": "bar" }
r = map m as k, v { v } // ["foo", "bar"]
89 changes: 89 additions & 0 deletions tests/snapshot/sentinel/collections.sentinel.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
># https://developer.hashicorp.com/sentinel/docs/language/collection-operations
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.number-sign.sentinel
>
># filter
#^^^^^^^^ source.sentinel comment.line.number-sign.sentinel
>filter list as value { condition } // Single-iterator, list
#^^^^^^ source.sentinel keyword.control.sentinel
# ^^^^^^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>filter list as idx, value { condition } // Double-iterator, list
#^^^^^^ source.sentinel keyword.control.sentinel
# ^^^^^^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>
>filter map as key { condition } // Single-iterator, map
#^^^^^^ source.sentinel keyword.control.sentinel
# ^ source.sentinel
# ^^^ source.sentinel keyword.control.sentinel
# ^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>filter map as key, value { condition } // Double-iterator, map
#^^^^^^ source.sentinel keyword.control.sentinel
# ^ source.sentinel
# ^^^ source.sentinel keyword.control.sentinel
# ^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>
># map
#^^^^^ source.sentinel comment.line.number-sign.sentinel
>l = [1, 2]
#^^ source.sentinel
# ^ source.sentinel keyword.operator.symbol.sentinel
# ^^ source.sentinel
# ^ source.sentinel constant.numeric.number.sentinel
# ^^ source.sentinel
# ^ source.sentinel constant.numeric.number.sentinel
# ^^ source.sentinel
>r = map l as v { v % 2 } // [false, true]
#^^ source.sentinel
# ^ source.sentinel keyword.operator.symbol.sentinel
# ^ source.sentinel
# ^^^ source.sentinel keyword.control.sentinel
# ^^^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^ source.sentinel
# ^ source.sentinel keyword.operator.symbol.sentinel
# ^ source.sentinel
# ^ source.sentinel constant.numeric.number.sentinel
# ^^^ source.sentinel
# ^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>
>m = { "a": "foo", "b": "bar" }
#^^ source.sentinel
# ^ source.sentinel keyword.operator.symbol.sentinel
# ^^^ source.sentinel
# ^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^^ source.sentinel
# ^ source.sentinel string.quoted.double.untitled
# ^^^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^^ source.sentinel
# ^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^^ source.sentinel
# ^ source.sentinel string.quoted.double.untitled
# ^^^ source.sentinel string.quoted.double.untitled
# ^ source.sentinel string.quoted.double.untitled
# ^^^ source.sentinel
>r = map m as k, v { v } // ["foo", "bar"]
#^^ source.sentinel
# ^ source.sentinel keyword.operator.symbol.sentinel
# ^ source.sentinel
# ^^^ source.sentinel keyword.control.sentinel
# ^^^ source.sentinel
# ^^ source.sentinel keyword.other.sentinel
# ^^^^^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>
14 changes: 14 additions & 0 deletions tests/snapshot/sentinel/comments.sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://developer.hashicorp.com/sentinel/docs/language/spec#comments

# Single line comment
comment

comment # Single line comment

// Single line comment
comment

/* multi
line
comment */
comment
28 changes: 28 additions & 0 deletions tests/snapshot/sentinel/comments.sentinel.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
># https://developer.hashicorp.com/sentinel/docs/language/spec#comments
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.number-sign.sentinel
>
># Single line comment
#^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.number-sign.sentinel
>comment
#^^^^^^^^ source.sentinel
>
>comment # Single line comment
#^^^^^^^^ source.sentinel
# ^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.number-sign.sentinel
>
>// Single line comment
#^^^^^^^^^^^^^^^^^^^^^^ source.sentinel comment.line.double-slash.sentinel
>comment
#^^^^^^^^ source.sentinel
>
>/* multi
#^^ source.sentinel comment.line.block.sentinel
# ^^^^^^^ source.sentinel comment.line.block.sentinel
>line
#^^^^^ source.sentinel comment.line.block.sentinel
> comment */
#^^^^^^^^^^^^ source.sentinel comment.line.block.sentinel
# ^^ source.sentinel comment.line.block.sentinel
>comment
#^^^^^^^^ source.sentinel
>
41 changes: 41 additions & 0 deletions tests/snapshot/sentinel/conditional.sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# https://developer.hashicorp.com/sentinel/docs/language/conditionals

# Single line if statements
if value is 18 { print("condition met") }
if value { print("condition met") }
if value["key"] > 12 { print("condition met") }

# Multi-line if statements
if value is 18 {
print("condition met")
}

if value {
print("condition met")
}

if value["key"] > 12 {
print("condition met")
}

# Multi-line if-elseif-else statements
if value is 18 { print("condition met") } else if value { print("condition met") } else { print("condition met") }

# Multi-line if-elseif-else statements
if value is 18 {
print("condition met")
} else if value {
print("condition met")
} else {
print("condition met")
}

// Case statements
case x { when "foo", "bar": return true; else: return false }

case x {
when "foo", "bar":
return true
else:
return false
}
Loading