first commit
This commit is contained in:
commit
4ff159dd4a
20 changed files with 6529 additions and 0 deletions
7
tests/arrays.sui
Normal file
7
tests/arrays.sui
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Array test
|
||||
fn main(args: [string]) -> int do
|
||||
let arr = [1, 2, 3, 4];
|
||||
let empty = [];
|
||||
let x = arr[0];
|
||||
x
|
||||
end
|
||||
8
tests/basic_types.sui
Normal file
8
tests/basic_types.sui
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Basic type checking test
|
||||
fn main() -> int do
|
||||
let x = 5;
|
||||
let y = 10.5;
|
||||
let z = true;
|
||||
let s = "hello";
|
||||
x
|
||||
end
|
||||
12
tests/control_flow.sui
Normal file
12
tests/control_flow.sui
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Control flow test
|
||||
fn main() -> int do
|
||||
if true
|
||||
1
|
||||
else
|
||||
0
|
||||
|
||||
let i = 0;
|
||||
while i < 5
|
||||
i = i + 1;
|
||||
i
|
||||
end
|
||||
34
tests/enums.sui
Normal file
34
tests/enums.sui
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Enum test
|
||||
enum Color
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
end
|
||||
|
||||
enum Result<T, E>
|
||||
Ok(T),
|
||||
Err(E),
|
||||
end
|
||||
|
||||
struct Person
|
||||
name: string,
|
||||
age: int,
|
||||
end
|
||||
|
||||
fn main() -> int do
|
||||
let color = Color::Red();
|
||||
let res = Result::Ok(42);
|
||||
match res
|
||||
Result::Ok(value) => value,
|
||||
Result::Err(_) => 0,
|
||||
end
|
||||
let person = Person { name: "Bob", age: 25 };
|
||||
match color
|
||||
Color::Red() => 1,
|
||||
Color::Green() => 2,
|
||||
Color::Blue() => 3,
|
||||
end
|
||||
match person
|
||||
Person { name: _, age: age } => age,
|
||||
end
|
||||
end
|
||||
12
tests/functions.sui
Normal file
12
tests/functions.sui
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Function test
|
||||
fn add(x: int, y: int) -> int
|
||||
x + y
|
||||
|
||||
fn identity<T>(x: T) -> T
|
||||
x
|
||||
|
||||
fn main() -> int do
|
||||
let sum = add(5, 3);
|
||||
let id = identity(42);
|
||||
sum
|
||||
end
|
||||
16
tests/structs.sui
Normal file
16
tests/structs.sui
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Struct test
|
||||
struct Point
|
||||
x: int,
|
||||
y: int,
|
||||
end
|
||||
|
||||
struct Person<T>
|
||||
name: string,
|
||||
age: T,
|
||||
end
|
||||
|
||||
fn main() -> int do
|
||||
let p = Point { x: 5, y: 10 };
|
||||
let person = Person { name: "Alice", age: 30 };
|
||||
p.x
|
||||
end
|
||||
17
tests/traits.sui
Normal file
17
tests/traits.sui
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Trait and implementation test
|
||||
trait Show
|
||||
fn show(self) -> string
|
||||
end
|
||||
|
||||
struct Number
|
||||
value: int
|
||||
end
|
||||
|
||||
impl Number : Show
|
||||
fn show(self) -> string
|
||||
"number"
|
||||
end
|
||||
|
||||
fn main() -> int do
|
||||
42
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue