#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(dead_code)]
use goish::prelude::*;
Struct!{ type PathTest struct {
path, result string
} }
var!(ErrNotFound = errors::New("not found"));
Const! {
Sunday = iota;
Monday;
Tuesday;
}
pub fn divide(a: int64, b: int64) -> (int64, error) {
if b == 0 {
return (0, errors::New("divide by zero"));
}
return (a / b, nil);
}
pub fn main() {
let mut cases = slice!([]PathTest{PathTest!("a", "A"), PathTest!("b", "B")});
for (i, c) in range!(cases) {
Printf!("case %d: %s -> %s\n", i, c.path, c.result);
}
let mut nums = slice!([]int{1, 2, 3, 4, 5});
let mut total = 0;
for (_, n) in range!(nums) {
total += n;
}
Println!("total:", total);
let mut m = map!([string]int{"a" => 1, "b" => 2});
for (k, v) in range!(m) {
Println!(k, v);
}
let (q, err) = divide(10, 2);
if err != nil {
Println!("error:", err);
} else {
Println!("q =", q);
}
let (s, err) = strconv::Atoi("42");
if err == nil {
Println!(s);
}
for i in 0..3 {
Println!(i);
}
}