aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/literals_spec.yue
blob: 4c0b8c19aec16203ac26eddd57fbba337f370063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
describe "literals", ->
	it "should support integer literals", ->
		assert.same 123, 123

	it "should support float literals", ->
		assert.same 1.5, 1.5

	it "should support scientific notation", ->
		assert.same 1.5e2, 150

	it "should support negative numbers", ->
		assert.same -42, -42

	it "should support hexadecimal literals", ->
		assert.same 0xff, 255

	it "should support hexadecimal with uppercase", ->
		assert.same 0XFF, 255

	it "should support binary literals", ->
		assert.same 0b101, 5

	it "should support binary with uppercase", ->
		assert.same 0B101, 5

	it "should support number with underscores", ->
		assert.same 1_000_000, 1000000

	it "should support hex with underscores", ->
		assert.same 0xDE_AD_BE_EF, 0xDEADBEEF

	it "should support double quote strings", ->
		assert.same "hello", "hello"

	it "should support single quote strings", ->
		assert.same 'world', 'world'

	it "should support multi-line strings with [[", ->
		s = [[
			hello
			world
		]]
		assert.is_true s\match("hello")?

	it "should support multi-line strings with [=[", ->
		s = [==[
			test
		]==]
		assert.is_true s\match("test")?

	it "should support boolean true", ->
		assert.same true, true

	it "should support boolean false", ->
		assert.same false, false

	it "should support nil", ->
		assert.same nil, nil

	it "should support empty table", ->
		t = {}
		assert.same #t, 0

	it "should support table with keys", ->
		t = {a: 1, b: 2}
		assert.same t.a, 1
		assert.same t.b, 2

	it "should support array literal", ->
		t = {1, 2, 3}
		assert.same t[1], 1
		assert.same t[2], 2
		assert.same t[3], 3

	it "should support mixed table", ->
		t = {
			1, 2, 3
			key: "value"
		}
		assert.same t[1], 1
		assert.same t.key, "value"