mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: cleanup
This commit is contained in:
parent
dee411149e
commit
cf23c289ec
@ -12,7 +12,9 @@ fn cmp(a, b f32) bool {
|
||||
|
||||
fn test_ortho() {
|
||||
projection := glm.ortho(0, 200, 400, 0)
|
||||
println(projection.data[0])
|
||||
$if debug {
|
||||
println(projection.data[0])
|
||||
}
|
||||
assert cmp(projection.data[0], 0.01)
|
||||
assert cmp(projection.data[1], 0.000000)
|
||||
assert cmp(projection.data[2], 0.000000)
|
||||
@ -53,18 +55,26 @@ fn test_ortho() {
|
||||
}
|
||||
|
||||
fn test_rotate() {
|
||||
println('rotate')
|
||||
$if debug {
|
||||
println('rotate')
|
||||
}
|
||||
mut m := glm.identity()
|
||||
m = glm.scale(m, glm.vec3(2, 2, 2))
|
||||
println(m)
|
||||
$if debug {
|
||||
println(m)
|
||||
}
|
||||
m = glm.rotate_z(m, 1)
|
||||
println(m)
|
||||
$if debug {
|
||||
println(m)
|
||||
}
|
||||
}
|
||||
|
||||
fn test_translate() {
|
||||
mut m := glm.identity()
|
||||
m = glm.translate(m, glm.vec3(0, 0, - 0.5))
|
||||
println(m)
|
||||
$if debug {
|
||||
println(m)
|
||||
}
|
||||
// TODO
|
||||
// mat4x4((1.000000, 0.000000, 0.000000, 0.000000),
|
||||
// (0.000000, 1.000000, 0.000000, 0.000000),
|
||||
|
@ -28,12 +28,16 @@ fn test_fraction_add() {
|
||||
f1 = fractions.fraction(9,3)
|
||||
f2 = fractions.fraction(1,3)
|
||||
sum = f1 + f2
|
||||
println(sum.f64())
|
||||
$if debug {
|
||||
println(sum.f64())
|
||||
}
|
||||
assert sum.str().eq('10/3')
|
||||
f1 = fractions.fraction(3,7)
|
||||
f2 = fractions.fraction(1,4)
|
||||
sum = f1 + f2
|
||||
println(sum.f64())
|
||||
$if debug {
|
||||
println(sum.f64())
|
||||
}
|
||||
assert sum.str().eq('19/28')
|
||||
}
|
||||
|
||||
@ -51,12 +55,16 @@ fn test_fraction_subtract() {
|
||||
f1 = fractions.fraction(9,3)
|
||||
f2 = fractions.fraction(1,3)
|
||||
diff = f1 - f2
|
||||
println(diff.f64())
|
||||
$if debug {
|
||||
println(diff.f64())
|
||||
}
|
||||
assert diff.str().eq('8/3')
|
||||
f1 = fractions.fraction(3,7)
|
||||
f2 = fractions.fraction(1,4)
|
||||
diff = f1 - f2
|
||||
println(diff.f64())
|
||||
$if debug {
|
||||
println(diff.f64())
|
||||
}
|
||||
assert diff.str().eq('5/28')
|
||||
}
|
||||
|
||||
@ -79,7 +87,9 @@ fn test_fraction_multiply() {
|
||||
f1 = fractions.fraction(3,7)
|
||||
f2 = fractions.fraction(1,4)
|
||||
product = f1.multiply(f2)
|
||||
println(product.f64())
|
||||
$if debug {
|
||||
println(product.f64())
|
||||
}
|
||||
assert product.str().eq('3/28')
|
||||
}
|
||||
|
||||
@ -102,7 +112,9 @@ fn test_fraction_divide() {
|
||||
f1 = fractions.fraction(3,7)
|
||||
f2 = fractions.fraction(1,4)
|
||||
re = f1.divide(f2)
|
||||
println(re.f64())
|
||||
$if debug {
|
||||
println(re.f64())
|
||||
}
|
||||
assert re.str().eq('12/7')
|
||||
}
|
||||
|
@ -125,7 +125,9 @@ pub fn (s Socket) listen() ?int {
|
||||
if res < 0 {
|
||||
return error('socket: listen failed')
|
||||
}
|
||||
println('listen res = $res')
|
||||
$if debug {
|
||||
println('listen res = $res')
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@ -144,7 +146,9 @@ pub fn (s Socket) listen_backlog(backlog int) ?int {
|
||||
|
||||
// helper method to create, bind, and listen given port number
|
||||
pub fn listen(port int) ?Socket {
|
||||
println('net.listen($port)')
|
||||
$if debug {
|
||||
println('net.listen($port)')
|
||||
}
|
||||
s := socket(AF_INET, SOCK_STREAM, 0) or {
|
||||
return error(err)
|
||||
}
|
||||
@ -159,7 +163,9 @@ println('net.listen($port)')
|
||||
|
||||
// accept first connection request from socket queue
|
||||
pub fn (s Socket) accept() ?Socket {
|
||||
println('accept()')
|
||||
$if debug {
|
||||
println('accept()')
|
||||
}
|
||||
addr := C.sockaddr_storage{}
|
||||
size := 128 // sizeof(sockaddr_storage)
|
||||
sockfd := C.accept(s.sockfd, &addr, &size)
|
||||
@ -265,12 +271,18 @@ pub fn (s Socket) write(str string) {
|
||||
pub fn (s Socket) read_line() string {
|
||||
mut res := ''
|
||||
for {
|
||||
println('.')
|
||||
$if debug {
|
||||
println('.')
|
||||
}
|
||||
mut buf := malloc(MAX_READ)
|
||||
n := int(C.recv(s.sockfd, buf, MAX_READ-1, 0))
|
||||
println('numbytes=$n')
|
||||
$if debug {
|
||||
println('numbytes=$n')
|
||||
}
|
||||
if n == -1 {
|
||||
println('recv failed')
|
||||
$if debug {
|
||||
println('recv failed')
|
||||
}
|
||||
// TODO
|
||||
return ''
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ pub fn (ctx Context) html(html string) {
|
||||
|
||||
}
|
||||
|
||||
pub fn run<T>(port int) {
|
||||
pub fn run<T>(port int) {
|
||||
println('Running vweb app on http://localhost:$port ...')
|
||||
l := net.listen(port) or { panic('failed to listen') }
|
||||
mut app := T{}
|
||||
@ -126,7 +126,9 @@ pub fn run<T>(port int) {
|
||||
method: vals[0]
|
||||
url: vals[1]
|
||||
}
|
||||
println('vweb action = "$action"')
|
||||
$if debug {
|
||||
println('vweb action = "$action"')
|
||||
}
|
||||
//mut app := T{
|
||||
app.vweb = Context{
|
||||
req: req
|
||||
@ -140,7 +142,9 @@ pub fn run<T>(port int) {
|
||||
app.vweb.parse_form(s)
|
||||
}
|
||||
if vals.len < 2 {
|
||||
println('no vals for http')
|
||||
$if debug {
|
||||
println('no vals for http')
|
||||
}
|
||||
conn.close()
|
||||
continue
|
||||
}
|
||||
@ -173,14 +177,18 @@ fn (ctx mut Context) parse_form(s string) {
|
||||
str_form = str_form.replace('+', ' ')
|
||||
words := str_form.split('&')
|
||||
for word in words {
|
||||
println('parse form keyval="$word"')
|
||||
$if debug {
|
||||
println('parse form keyval="$word"')
|
||||
}
|
||||
keyval := word.trim_space().split('=')
|
||||
if keyval.len != 2 { continue }
|
||||
key := keyval[0]
|
||||
val := urllib.query_unescape(keyval[1]) or {
|
||||
continue
|
||||
}
|
||||
println('http form "$key" => "$val"')
|
||||
}
|
||||
$if debug {
|
||||
println('http form "$key" => "$val"')
|
||||
}
|
||||
ctx.form[key] = val
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user