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