Skip to content

Commit 506ab7b

Browse files
committed
fix scala parse json test
1 parent f40e313 commit 506ab7b

1 file changed

Lines changed: 77 additions & 77 deletions

File tree

src/test/resources/io/viash/helpers/languages/scala/test_ViashParseJson.scala

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -136,86 +136,86 @@ def testType(testName: String, expectedType: String, actual: Any): Unit = {
136136
val par = parsed("par").asInstanceOf[Map[String, Any]]
137137
val meta = parsed("meta").asInstanceOf[Map[String, Any]]
138138

139-
// Test 1: Basic key-value pairs
140-
println("=== Test 1: Basic key-value pairs ===")
141-
runTest("par.input", "file.txt", par("input"))
142-
runTest("par.number", 42, par("number"))
143-
runTest("par.flag", true, par("flag"))
144-
runTest("par.empty_value", "", par("empty_value"))
145-
runTest("meta.name", "test_component", meta("name"))
146-
runTest("meta.version", "1.0.0", meta("version"))
147-
println()
148-
149-
// Test 2: Arrays
150-
println("=== Test 2: Arrays ===")
151-
val arraySimple = par("array_simple").asInstanceOf[List[Any]]
152-
runTest("par.array_simple length", 3, arraySimple.length)
153-
runTest("par.array_simple[0]", "a", arraySimple(0))
154-
runTest("par.array_simple[1]", "b", arraySimple(1))
155-
runTest("par.array_simple[2]", "c", arraySimple(2))
156-
157-
val arrayNumbers = par("array_numbers").asInstanceOf[List[Any]]
158-
runTest("par.array_numbers length", 3, arrayNumbers.length)
159-
runTest("par.array_numbers[0]", 1, arrayNumbers(0))
160-
runTest("par.array_numbers[1]", 2, arrayNumbers(1))
161-
runTest("par.array_numbers[2]", 3, arrayNumbers(2))
162-
163-
val arrayMixed = par("array_mixed").asInstanceOf[List[Any]]
164-
runTest("par.array_mixed length", 3, arrayMixed.length)
165-
println()
166-
167-
// Test 3: Nested structures
168-
println("=== Test 3: Nested structures ===")
169-
val nested = par("nested").asInstanceOf[Map[String, Any]]
170-
val level1 = nested("level1").asInstanceOf[Map[String, Any]]
171-
runTest("par.nested.level1.level2", "deep_value", level1("level2"))
172-
println()
173-
174-
// Test 4: Quoted strings
175-
println("=== Test 4: Quoted strings ===")
176-
runTest("par.path_with_spaces", "/path/with spaces/file.txt", par("path_with_spaces"))
177-
runTest("par.quotes", "He said \"hello\"", par("quotes"))
178-
runTest("par.newlines", "line1\nline2", par("newlines"))
179-
runTest("par.tabs", "col1\tcol2", par("tabs"))
180-
println()
181-
182-
// Test 5: Type conversions
183-
println("=== Test 5: Type conversions ===")
184-
testType("par.string", "String", par("string"))
185-
testType("par.integer", "Int", par("integer"))
186-
testType("par.float", "Double", par("float"))
187-
testType("par.bool_true", "Boolean", par("bool_true"))
188-
runTest("par.bool_false", false, par("bool_false"))
189-
runTest("par.null_value", null, par("null_value"))
190-
println()
139+
// Test 1: Basic key-value pairs
140+
println("=== Test 1: Basic key-value pairs ===")
141+
runTest("par.input", "file.txt", par("input"))
142+
runTest("par.number", 42, par("number"))
143+
runTest("par.flag", true, par("flag"))
144+
runTest("par.empty_value", "", par("empty_value"))
145+
runTest("meta.name", "test_component", meta("name"))
146+
runTest("meta.version", "1.0.0", meta("version"))
147+
println()
148+
149+
// Test 2: Arrays
150+
println("=== Test 2: Arrays ===")
151+
val arraySimple = par("array_simple").asInstanceOf[List[Any]]
152+
runTest("par.array_simple length", 3, arraySimple.length)
153+
runTest("par.array_simple[0]", "a", arraySimple(0))
154+
runTest("par.array_simple[1]", "b", arraySimple(1))
155+
runTest("par.array_simple[2]", "c", arraySimple(2))
191156

192-
// Test 6: Root-level values
193-
println("=== Test 6: Root-level values ===")
194-
runTest("simple_key", "simple_value", parsed("simple_key"))
195-
runTest("number_key", 123, parsed("number_key"))
196-
runTest("bool_key", true, parsed("bool_key"))
197-
println()
157+
val arrayNumbers = par("array_numbers").asInstanceOf[List[Any]]
158+
runTest("par.array_numbers length", 3, arrayNumbers.length)
159+
runTest("par.array_numbers[0]", 1, arrayNumbers(0))
160+
runTest("par.array_numbers[1]", 2, arrayNumbers(1))
161+
runTest("par.array_numbers[2]", 3, arrayNumbers(2))
198162

199-
// Test 7: Edge cases
200-
println("=== Test 7: Edge cases ===")
201-
runTest("par.empty_string", "", par("empty_string"))
202-
runTest("par.zero", 0, par("zero"))
203-
val emptyArray = par("empty_array").asInstanceOf[List[Any]]
204-
runTest("par.empty_array length", 0, emptyArray.length)
205-
testType("par.empty_object", "Map", par("empty_object"))
206-
println()
163+
val arrayMixed = par("array_mixed").asInstanceOf[List[Any]]
164+
runTest("par.array_mixed length", 3, arrayMixed.length)
165+
println()
166+
167+
// Test 3: Nested structures
168+
println("=== Test 3: Nested structures ===")
169+
val nested = par("nested").asInstanceOf[Map[String, Any]]
170+
val level1 = nested("level1").asInstanceOf[Map[String, Any]]
171+
runTest("par.nested.level1.level2", "deep_value", level1("level2"))
172+
println()
173+
174+
// Test 4: Quoted strings
175+
println("=== Test 4: Quoted strings ===")
176+
runTest("par.path_with_spaces", "/path/with spaces/file.txt", par("path_with_spaces"))
177+
runTest("par.quotes", "He said \"hello\"", par("quotes"))
178+
runTest("par.newlines", "line1\nline2", par("newlines"))
179+
runTest("par.tabs", "col1\tcol2", par("tabs"))
180+
println()
181+
182+
// Test 5: Type conversions
183+
println("=== Test 5: Type conversions ===")
184+
testType("par.string", "String", par("string"))
185+
testType("par.integer", "Int", par("integer"))
186+
testType("par.float", "Double", par("float"))
187+
testType("par.bool_true", "Boolean", par("bool_true"))
188+
runTest("par.bool_false", false, par("bool_false"))
189+
runTest("par.null_value", null, par("null_value"))
190+
println()
191+
192+
// Test 6: Root-level values
193+
println("=== Test 6: Root-level values ===")
194+
runTest("simple_key", "simple_value", parsed("simple_key"))
195+
runTest("number_key", 123, parsed("number_key"))
196+
runTest("bool_key", true, parsed("bool_key"))
197+
println()
198+
199+
// Test 7: Edge cases
200+
println("=== Test 7: Edge cases ===")
201+
runTest("par.empty_string", "", par("empty_string"))
202+
runTest("par.zero", 0, par("zero"))
203+
val emptyArray = par("empty_array").asInstanceOf[List[Any]]
204+
runTest("par.empty_array length", 0, emptyArray.length)
205+
testType("par.empty_object", "Map", par("empty_object"))
206+
println()
207207

208-
// Summary
209-
println("==================================================")
210-
println(s"Tests completed: ${testsPass + testsFail}")
211-
println(s"Tests passed: $testsPass")
212-
if (testsFail > 0) {
213-
println(s"${Colors.RED}Tests failed: $testsFail${Colors.NC}")
214-
sys.exit(1)
215-
} else {
216-
println(s"${Colors.GREEN}All tests passed!${Colors.NC}")
217-
sys.exit(0)
218-
}
208+
// Summary
209+
println("==================================================")
210+
println(s"Tests completed: ${testsPass + testsFail}")
211+
println(s"Tests passed: $testsPass")
212+
if (testsFail > 0) {
213+
println(s"${Colors.RED}Tests failed: $testsFail${Colors.NC}")
214+
sys.exit(1)
215+
} else {
216+
println(s"${Colors.GREEN}All tests passed!${Colors.NC}")
217+
sys.exit(0)
218+
}
219219
} finally {
220220
java.nio.file.Files.deleteIfExists(tempFile)
221221
}

0 commit comments

Comments
 (0)