Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tdenniston committed Jan 27, 2016
1 parent 3eb594c commit 46bfa25
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/conditionals.bish
@@ -0,0 +1,35 @@
def test() {
x = 0
y = 1
if (y == 1) {
x = 2
}
assert(x == 2)

if (y == 2) {
x = 3
}
assert(x == 2)

if (y == 0) {
x = 0
} else if (y == 1) {
x = 1
}
assert(x == 1)

for (i in 0 .. 3) {
if (i == 0) {
assert(i == 0)
} else if (i == 1) {
assert(i == 1)
} else if (i == 2) {
assert(i == 2)
} else {
assert(i == 3)
}
}
println("Conditional tests passed.")
}

test()
24 changes: 24 additions & 0 deletions tests/return_vals.bish
@@ -0,0 +1,24 @@
# Tests for return values.

def lastchar(x) {
if (x != "") {
y = @(echo -ne "$x" | tail -c 1)
x = "$y"
}
return x
}

def test() {
h = lastchar("hello")
assert(h == "o")
assert(lastchar("hello") == "o")
assert(lastchar("") == "")
println("Return value tests passed.")
}

# Include some module-level tests
h = lastchar("hello")
assert(h == "o")
assert(lastchar("hello") == "o")

test()
3 changes: 3 additions & 0 deletions tests/tests.bish
Expand Up @@ -46,6 +46,9 @@ def run_all() {

import return_vals
return_vals.test()

import conditionals
conditionals.test()
}

change_dir()
Expand Down

0 comments on commit 46bfa25

Please sign in to comment.