Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hidetatz committed Jul 30, 2023
1 parent 7fc7ebf commit 3cab438
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/dict.sb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import assert

as = assert.assert

d = {1: "a", 2: true, 3: [1, 2, 3], [1, 2, 3]: [4, 5, 6], 5: {"a": "b"}}
as("a", d[1])
as(true, d[2])
as([1, 2, 3], d[3])
as([4, 5, 6], d[[1, 2, 3]])
as([4, 5, 6], d[d[3]])
as("b", d[5]["a"])

print("dict test succeeded")
71 changes: 71 additions & 0 deletions tests/for.sb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import assert

as = assert.assert

l = ["a", "b", "c", "d", "e"]

idx = 0
for i, e in l {
if idx == 0 {
as(0, i)
as("a", e)
} elif idx == 1 {
as(1, i)
as("b", e)
} elif idx == 2 {
as(2, i)
as("c", e)
} elif idx == 3 {
as(3, i)
as("d", e)
} elif idx == 4 {
as(4, i)
as("e", e)
} else {
print("must not come here")
exit(1)
}
idx += 1
}

as(5, idx)

for i, e in [] {
print("must not come here")
exit(1)
}

idx = 0
for i, e in "abc" {
if idx == 0 {
as(0, i)
as("a", e)
} elif idx == 1 {
as(1, i)
as("b", e)
} elif idx == 2 {
as(2, i)
as("c", e)
} else {
print("must not come here")
exit(1)
}
idx += 1
}

a = 0
for i, e in l {
a = e
if i == 2 {
break
}
}
as("c", a)

for i, e in l {
continue
print("must not come here")
exit(1)
}

print("for test succeeded")
39 changes: 39 additions & 0 deletions tests/if.sb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import assert

as = assert.assert

a = 1

as(1, a)

if true {
a = 2
}

as(2, a)

if a == 2 {
a = 3
}

as(3, a)

if a == 1 {
a = 4
} elif a == 2 {
a = 5
} elif a == 3 {
a = 6
}

as(6, a)

if a == 1 {
a = 7
} else {
a = 8
}

as(8, a)

print("if test succeeded")
5 changes: 5 additions & 0 deletions tests/list.sb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ as([], [1, 2, 3][0:0])
as([2], [1, 2, 3][1:2])
as([2, 3], [1, 2, 3][1:3])

a, b, c := [1, 2, 3]
as(a, 1)
as(b, 2)
as(c, 3)

print("list test succeeded")
5 changes: 5 additions & 0 deletions tests/str.sb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ as("aaaaaaaaa", 3 * "a" * 3)
as("a", "abc"[0])
as("ab", "abc"[0:2])

a, b, c := "123"
as(a, "1")
as(b, "2")
as(c, "3")

print("str test succeeded")

0 comments on commit 3cab438

Please sign in to comment.