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:
56
packages/testing/README.md
Normal file
56
packages/testing/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# testing
|
||||
|
||||
Testing utilities and assertions for Lux.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
lux pkg add testing 0.1.0
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```lux
|
||||
import testing
|
||||
|
||||
fn testMyFunction(): Unit with {Console, Test} = {
|
||||
testing.describe("MyFunction", fn() => {
|
||||
testing.it("should return correct value", fn() => {
|
||||
let result = myFunction(5)
|
||||
testing.assertEqual(result, 10, "5 * 2 should be 10")
|
||||
})
|
||||
|
||||
testing.it("should handle edge cases", fn() => {
|
||||
let result = myFunction(0)
|
||||
testing.assertEqual(result, 0, "0 * 2 should be 0")
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Assertions
|
||||
|
||||
| Function | Description |
|
||||
|----------|-------------|
|
||||
| `assert(cond, msg)` | Assert condition is true |
|
||||
| `assertEqual(a, b, msg)` | Assert two values are equal |
|
||||
| `assertSome(opt, msg)` | Assert Option is Some |
|
||||
| `assertNone(opt, msg)` | Assert Option is None |
|
||||
| `assertOk(result, msg)` | Assert Result is Ok |
|
||||
| `assertErr(result, msg)` | Assert Result is Err |
|
||||
| `assertEmpty(list, msg)` | Assert list is empty |
|
||||
| `assertLength(list, n, msg)` | Assert list has length n |
|
||||
| `assertContains(s, sub, msg)` | Assert string contains substring |
|
||||
| `assertStartsWith(s, pre, msg)` | Assert string starts with prefix |
|
||||
| `assertEndsWith(s, suf, msg)` | Assert string ends with suffix |
|
||||
|
||||
## Test Structure
|
||||
|
||||
| Function | Description |
|
||||
|----------|-------------|
|
||||
| `describe(name, tests)` | Group related tests |
|
||||
| `it(desc, test)` | Define individual test |
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
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()
|
||||
}
|
||||
8
packages/testing/lux.toml
Normal file
8
packages/testing/lux.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[project]
|
||||
name = "testing"
|
||||
version = "0.1.0"
|
||||
description = "Testing utilities and assertions for Lux"
|
||||
authors = ["Lux Core Team"]
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
Reference in New Issue
Block a user