feat: initialize Lux package registry
- Add registry README with API documentation - Add initial packages: json, http-client, testing - Add package index.json for registry server Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
71
packages/testing/lib.lux
Normal file
71
packages/testing/lib.lux
Normal file
@@ -0,0 +1,71 @@
|
||||
// Testing utilities for Lux
|
||||
//
|
||||
// Provides assertion functions and test helpers.
|
||||
|
||||
// Assert that a condition is true
|
||||
pub fn assert(condition: Bool, message: String): Unit with Test = {
|
||||
Test.assertTrue(condition, message)
|
||||
}
|
||||
|
||||
// Assert two values are equal
|
||||
pub fn assertEqual<T>(actual: T, expected: T, message: String): Unit with Test = {
|
||||
Test.assertEqual(actual, expected, message)
|
||||
}
|
||||
|
||||
// Assert a value is Some
|
||||
pub fn assertSome<T>(opt: Option<T>, message: String): Unit with Test = {
|
||||
Test.assertTrue(Option.isSome(opt), message)
|
||||
}
|
||||
|
||||
// Assert a value is None
|
||||
pub fn assertNone<T>(opt: Option<T>, message: String): Unit with Test = {
|
||||
Test.assertTrue(Option.isNone(opt), message)
|
||||
}
|
||||
|
||||
// Assert a Result is Ok
|
||||
pub fn assertOk<T, E>(result: Result<T, E>, message: String): Unit with Test = {
|
||||
Test.assertTrue(Result.isOk(result), message)
|
||||
}
|
||||
|
||||
// Assert a Result is Err
|
||||
pub fn assertErr<T, E>(result: Result<T, E>, message: String): Unit with Test = {
|
||||
Test.assertTrue(Result.isErr(result), message)
|
||||
}
|
||||
|
||||
// Assert a list is empty
|
||||
pub fn assertEmpty<T>(list: List<T>, message: String): Unit with Test = {
|
||||
Test.assertTrue(List.isEmpty(list), message)
|
||||
}
|
||||
|
||||
// Assert a list has specific length
|
||||
pub fn assertLength<T>(list: List<T>, expected: Int, message: String): Unit with Test = {
|
||||
Test.assertEqual(List.length(list), expected, message)
|
||||
}
|
||||
|
||||
// Assert a string contains a substring
|
||||
pub fn assertContains(haystack: String, needle: String, message: String): Unit with Test = {
|
||||
Test.assertTrue(String.contains(haystack, needle), message)
|
||||
}
|
||||
|
||||
// Assert a string starts with a prefix
|
||||
pub fn assertStartsWith(s: String, prefix: String, message: String): Unit with Test = {
|
||||
Test.assertTrue(String.startsWith(s, prefix), message)
|
||||
}
|
||||
|
||||
// Assert a string ends with a suffix
|
||||
pub fn assertEndsWith(s: String, suffix: String, message: String): Unit with Test = {
|
||||
Test.assertTrue(String.endsWith(s, suffix), message)
|
||||
}
|
||||
|
||||
// Run a test suite
|
||||
pub fn describe(name: String, tests: fn(): Unit with Test): Unit with {Console, Test} = {
|
||||
Console.print("Running: " ++ name)
|
||||
tests()
|
||||
Console.print("Passed: " ++ name)
|
||||
}
|
||||
|
||||
// Individual test case
|
||||
pub fn it(description: String, test: fn(): Unit with Test): Unit with {Console, Test} = {
|
||||
Console.print(" - " ++ description)
|
||||
test()
|
||||
}
|
||||
Reference in New Issue
Block a user