ci: fix compiling blog/, *and* comptime_if_is_test.v. Add vweb_app_test.v .
parent
63cb04196b
commit
6450fda938
|
@ -7,13 +7,13 @@ import json
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
vweb.Context
|
vweb.Context
|
||||||
mut:
|
pub mut:
|
||||||
db sqlite.DB [server_var]
|
db sqlite.DB [server_var]
|
||||||
user_id string
|
user_id string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
vweb.run<App>(8081)
|
vweb.run(&App{}, 8081)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -5749,11 +5749,13 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||||
comptime_field_name = left.expr.str()
|
comptime_field_name = left.expr.str()
|
||||||
c.comptime_fields_type[comptime_field_name] = got_type
|
c.comptime_fields_type[comptime_field_name] = got_type
|
||||||
is_comptime_type_is_expr = true
|
is_comptime_type_is_expr = true
|
||||||
} else if branch.cond.right is ast.TypeNode && left is ast.TypeNode {
|
} else if branch.cond.right is ast.TypeNode && left is ast.TypeNode
|
||||||
|
&& sym.kind == .interface_ {
|
||||||
// is interface
|
// is interface
|
||||||
checked_type := c.unwrap_generic((left as ast.TypeNode).typ)
|
checked_type := c.unwrap_generic((left as ast.TypeNode).typ)
|
||||||
should_skip = !c.table.type_implements_interface(checked_type,
|
should_skip = !c.table.type_implements_interface(checked_type,
|
||||||
got_type)
|
got_type)
|
||||||
|
eprintln('> checked_type: $checked_type | got_type: $got_type | should_skip: $should_skip')
|
||||||
} else if left is ast.TypeNode {
|
} else if left is ast.TypeNode {
|
||||||
is_comptime_type_is_expr = true
|
is_comptime_type_is_expr = true
|
||||||
left_type := c.unwrap_generic(left.typ)
|
left_type := c.unwrap_generic(left.typ)
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
import time
|
||||||
|
import sqlite
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
vweb.Context
|
||||||
|
pub mut:
|
||||||
|
db sqlite.DB [server_var]
|
||||||
|
user_id string
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Article {
|
||||||
|
id int
|
||||||
|
title string
|
||||||
|
text string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_a_vweb_application_compiles() {
|
||||||
|
go fn() {
|
||||||
|
time.sleep(2 * time.second)
|
||||||
|
exit(0)
|
||||||
|
}()
|
||||||
|
vweb.run(&App{}, 18081)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut app App) init_server() {
|
||||||
|
app.db = sqlite.connect('blog.db') or { panic(err) }
|
||||||
|
app.db.create_table('article', [
|
||||||
|
'id integer primary key',
|
||||||
|
"title text default ''",
|
||||||
|
"text text default ''",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut app App) before_request() {
|
||||||
|
app.user_id = app.get_cookie('id') or { '0' }
|
||||||
|
}
|
||||||
|
|
||||||
|
['/new_article'; post]
|
||||||
|
pub fn (mut app App) new_article() vweb.Result {
|
||||||
|
title := app.form['title']
|
||||||
|
text := app.form['text']
|
||||||
|
if title == '' || text == '' {
|
||||||
|
return app.text('Empty text/title')
|
||||||
|
}
|
||||||
|
article := Article{
|
||||||
|
title: title
|
||||||
|
text: text
|
||||||
|
}
|
||||||
|
println('posting article')
|
||||||
|
println(article)
|
||||||
|
sql app.db {
|
||||||
|
insert article into Article
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.redirect('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut app App) time() {
|
||||||
|
app.text(time.now().format())
|
||||||
|
}
|
Loading…
Reference in New Issue