Skip to content

Commit

Permalink
Moved tests to separate files for every fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Jul 3, 2024
1 parent 68be861 commit 231ca42
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/test/kotlin/ResourcesTest.kt → src/test/kotlin/FileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ import org.junit.jupiter.api.Test
import java.io.File
import java.net.URI

object ResourcesTest {
object FileTest {

@Test
fun testResources() {
fun testFiles() {
val core = this::class.java.getResourceAsStream("core.rx")!!
.bufferedReader().use { it.readText() }

val scope = Scope(null)

parse(tokenize(core), scope)

println("Running file tests...")
for (file in listResourceFiles()) {
val content = file.readText()
parse(tokenize(content), scope)
println("Passed ${file.nameWithoutExtension}")
try {
parse(tokenize(content), scope)
println("Passed tests in ${file.nameWithoutExtension}")
} catch (e: Exception) {
println("Failed tests in ${file.nameWithoutExtension}")
throw e
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/array.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "array?"
(array? [1 2 3])
(array? [])

(not (array? 1))
(not (array? "hello"))
(not (array? (identity "hello")))
(not (array? (fn [] [true]))))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/boolean.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "boolean?"
(boolean? true)
(boolean? false)

(not (boolean? 1))
(not (boolean? "hello"))
(not (boolean? (identity "hello")))
(not (boolean? (fn [] true))))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/double.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "double?"
(double? 4.235)

(not (double? 1058259824305968260))
(not (double? 1))
(not (double? "hello"))
(not (double? (identity "hello")))
(not (double? (fn [] 1.0))))
7 changes: 7 additions & 0 deletions src/test/resources/tests/core/fn.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(test "fn?"
(fn? (fn [] 1))
(fn? (fn [& more] 1 2 3 4 [5 6]))

(not (fn? 1))
(not (fn? "hello"))
(not (fn? (identity "hello"))))
5 changes: 5 additions & 0 deletions src/test/resources/tests/core/if.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(test "if"
(if true true false)
(if nil false true)
(throws? (fn [] (if false (throw) false)))
(throws? (fn [] (if true false (throw)))))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/int.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "int?"
(int? 1)

(not (int? 1058259824305968260))
(not (int? 4.235))
(not (int? "hello"))
(not (int? (identity "hello")))
(not (int? (fn [] 1))))
8 changes: 4 additions & 4 deletions src/test/resources/tests/core/is.rx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests all functions that use 'is?'
(test "is?"
(is? "hello" "java.lang.String")
(is? 1058259824305968260 "java.lang.Number")

(test "str?"
(str? "hello")
(not (str? 1)))
(not (is? 1 "java.lang.String")))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/long.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "long?"
(long? 1058259824305968260)

(not (long? 1))
(not (long? 4.235))
(not (long? "hello"))
(not (long? (identity "hello")))
(not (long? (fn [] 1058259824305968260))))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/map.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "map?"
(map? {"a" 1 "b" 2})
(map? {})

(not (map? 1))
(not (map? "hello"))
(not (map? (identity "hello")))
(not (map? (fn [] {"a" 1}))))
5 changes: 5 additions & 0 deletions src/test/resources/tests/core/not.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(test "not"
(not false)
(not (not true))

(throws? (fn [] (not "hello"))))
8 changes: 8 additions & 0 deletions src/test/resources/tests/core/num.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(test "num?"
(num? 1058259824305968260)
(num? 1)
(num? 4.235)

(not (num? "hello"))
(not (num? (identity "hello")))
(not (num? (fn [] 1))))
7 changes: 7 additions & 0 deletions src/test/resources/tests/core/str.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(test "str?"
(str? "hello")
(str? (identity "hello"))

(not (str? 1))
(not (str? (identity 1)))
(not (str? (fn [] "hello"))))
5 changes: 3 additions & 2 deletions src/test/resources/tests/core/test.rx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(test "test"
(not (throws? (fn [] (test "success" true))))
(throws? (fn [] (test "fails" false))))
(throws? (fn [] (test "fails" false)))

(not (throws? (fn [] (test "success" true)))))
4 changes: 4 additions & 0 deletions src/test/resources/tests/core/throw.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(test "throw"
(throws? (fn [] (throw)))

(not (throws? (fn [] 1))))
4 changes: 4 additions & 0 deletions src/test/resources/tests/core/throws.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(test "throws?"
(throws? (fn [] (throw)))

(not (throws? (fn [] 1))))

0 comments on commit 231ca42

Please sign in to comment.