1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: fix compiling blog/, *and* comptime_if_is_test.v. Add vweb_app_test.v .

This commit is contained in:
Delyan Angelov 2021-05-11 13:59:02 +03:00
parent 63cb04196b
commit 6450fda938
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 68 additions and 3 deletions

View File

@ -7,13 +7,13 @@ import json
struct App {
vweb.Context
mut:
pub mut:
db sqlite.DB [server_var]
user_id string
}
fn main() {
vweb.run<App>(8081)
vweb.run(&App{}, 8081)
}
/*

View File

@ -5749,11 +5749,13 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
comptime_field_name = left.expr.str()
c.comptime_fields_type[comptime_field_name] = got_type
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
checked_type := c.unwrap_generic((left as ast.TypeNode).typ)
should_skip = !c.table.type_implements_interface(checked_type,
got_type)
eprintln('> checked_type: $checked_type | got_type: $got_type | should_skip: $should_skip')
} else if left is ast.TypeNode {
is_comptime_type_is_expr = true
left_type := c.unwrap_generic(left.typ)

63
vlib/vweb/vweb_app_test.v Normal file
View File

@ -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())
}