Commit aa131aa2 authored by Roman Alifanov's avatar Roman Alifanov

Update README with @test decorator documentation

parent b37f6664
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- **Clean syntax** — Python-like readability with Go/Vala influences - **Clean syntax** — Python-like readability with Go/Vala influences
- **Classes & inheritance** — OOP with constructors and method calls - **Classes & inheritance** — OOP with constructors and method calls
- **Lambdas**`x => x * 2`, `(a, b) => a + b`, multiline blocks - **Lambdas**`x => x * 2`, `(a, b) => a + b`, multiline blocks
- **Decorators**`@retry`, `@log`, `@cache`, `@awk` - **Decorators**`@retry`, `@log`, `@cache`, `@awk`, `@test`
- **Pipe operator** — shell-like `|` for command chaining and functional composition - **Pipe operator** — shell-like `|` for command chaining and functional composition
- **Error handling**`try/except/finally/throw/defer` - **Error handling**`try/except/finally/throw/defer`
- **String interpolation**`"Hello, {name}!"` - **String interpolation**`"Hello, {name}!"`
...@@ -110,6 +110,12 @@ func fast_sum (text) { ...@@ -110,6 +110,12 @@ func fast_sum (text) {
} }
return total return total
} }
@test ("addition works correctly")
func test_add () {
result = 2 + 3
assert (result == 5, "2 + 3 should be 5")
}
``` ```
### Control Flow ### Control Flow
...@@ -185,6 +191,9 @@ content build . -o app.sh # all .ct in directory ...@@ -185,6 +191,9 @@ content build . -o app.sh # all .ct in directory
content run main.ct content run main.ct
content run main.ct -- arg1 arg2 # with arguments content run main.ct -- arg1 arg2 # with arguments
# Test
content test main.ct # run @test functions
# Build library # Build library
content --build-lib MyLib.ct # -> MyLib.sh content --build-lib MyLib.ct # -> MyLib.sh
...@@ -255,6 +264,46 @@ class Calculator { ...@@ -255,6 +264,46 @@ class Calculator {
Uses `mawk` (preferred) or `gawk` for maximum speed. Uses `mawk` (preferred) or `gawk` for maximum speed.
## @test — Built-in Testing
The `@test` decorator marks functions as tests. Run with `content test`.
```
@test ("string operations work")
func test_strings () {
text = "hello"
assert (text.len () == 5, "length should be 5")
assert (text.upper () == "HELLO", "uppercase should work")
}
@test ("awk functions work")
func test_awk () {
result = fast_sum ("1 2 3")
assert (result == 6, "sum should be 6")
}
```
**Features:**
- `assert(condition, message)` — works in both bash and @awk functions
- Colored output with timing for each test
- Tests are skipped in normal compilation (DCE)
- Combine with other decorators: `@test @awk`
**Output example:**
```
Running 3 tests...
RUN string operations work
PASS string operations work (2ms)
RUN awk functions work
PASS awk functions work (4ms)
RUN failing test
FAIL failing test (1ms)
expected 10 but got 5
2 of 3 tests passed
```
## Documentation ## Documentation
- [Language Specification](LANGUAGE_SPEC.md) - [Language Specification](LANGUAGE_SPEC.md)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- **Чистый синтаксис** — читаемость Python с влиянием Go/Vala - **Чистый синтаксис** — читаемость Python с влиянием Go/Vala
- **Классы и наследование** — ООП с конструкторами и вызовами методов - **Классы и наследование** — ООП с конструкторами и вызовами методов
- **Лямбды**`x => x * 2`, `(a, b) => a + b`, многострочные блоки - **Лямбды**`x => x * 2`, `(a, b) => a + b`, многострочные блоки
- **Декораторы**`@retry`, `@log`, `@cache`, `@awk` - **Декораторы**`@retry`, `@log`, `@cache`, `@awk`, `@test`
- **Pipe-оператор** — shell-like `|` для цепочек команд и функциональной композиции - **Pipe-оператор** — shell-like `|` для цепочек команд и функциональной композиции
- **Обработка ошибок**`try/except/finally/throw/defer` - **Обработка ошибок**`try/except/finally/throw/defer`
- **Строковая интерполяция**`"Привет, {name}!"` - **Строковая интерполяция**`"Привет, {name}!"`
...@@ -110,6 +110,12 @@ func fast_sum (text) { ...@@ -110,6 +110,12 @@ func fast_sum (text) {
} }
return total return total
} }
@test ("сложение работает")
func test_add () {
result = 2 + 3
assert (result == 5, "2 + 3 должно быть 5")
}
``` ```
### Управление потоком ### Управление потоком
...@@ -185,6 +191,9 @@ content build . -o app.sh # все .ct в директории ...@@ -185,6 +191,9 @@ content build . -o app.sh # все .ct в директории
content run main.ct content run main.ct
content run main.ct -- arg1 arg2 # с аргументами content run main.ct -- arg1 arg2 # с аргументами
# Тестирование
content test main.ct # запуск @test функций
# Сборка библиотеки # Сборка библиотеки
content --build-lib MyLib.ct # -> MyLib.sh content --build-lib MyLib.ct # -> MyLib.sh
...@@ -255,6 +264,46 @@ class Calculator { ...@@ -255,6 +264,46 @@ class Calculator {
Использует `mawk` (предпочтительно) или `gawk` для максимальной скорости. Использует `mawk` (предпочтительно) или `gawk` для максимальной скорости.
## @test — Встроенное тестирование
Декоратор `@test` помечает функции как тесты. Запуск через `content test`.
```
@test ("строковые операции работают")
func test_strings () {
text = "hello"
assert (text.len () == 5, "длина должна быть 5")
assert (text.upper () == "HELLO", "uppercase должен работать")
}
@test ("awk функции работают")
func test_awk () {
result = fast_sum ("1 2 3")
assert (result == 6, "сумма должна быть 6")
}
```
**Возможности:**
- `assert(condition, message)` — работает в bash и @awk функциях
- Цветной вывод с временем для каждого теста
- Тесты пропускаются при обычной компиляции (DCE)
- Комбинируется с другими декораторами: `@test @awk`
**Пример вывода:**
```
Running 3 tests...
RUN строковые операции работают
PASS строковые операции работают (2ms)
RUN awk функции работают
PASS awk функции работают (4ms)
RUN падающий тест
FAIL падающий тест (1ms)
ожидалось 10, получено 5
2 of 3 tests passed
```
## Документация ## Документация
- [Спецификация языка](LANGUAGE_SPEC.md) - [Спецификация языка](LANGUAGE_SPEC.md)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment