From 931cf86cc3012bb699fcc470fb638dd60eb61094 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 7 Jun 2020 15:44:33 +0200 Subject: [PATCH] tests: build vweb example --- cmd/tools/modules/testing/common.v | 9 +++- vlib/orm/orm_test.v | 87 +++++++++++++++--------------- vlib/v/parser/comptime.v | 24 ++++----- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 0f10ce8bde..e2ce07c820 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -231,7 +231,14 @@ pub fn v_build_failing_skipped(zargs string, folder string, skipped []string) bo mut mains := []string{} for f in files { if !f.contains('modules') && !f.contains('preludes') { - if f.contains('life_gg') || f.contains('/graph.v') || f.contains('/vweb/') || f.contains('/pg/') || f.contains('rune.v') { + //$if !linux { + // run pg example only on linux + if f.contains('/pg/') { + continue + } + //} + + if f.contains('life_gg') || f.contains('/graph.v') || f.contains('rune.v') { continue } diff --git a/vlib/orm/orm_test.v b/vlib/orm/orm_test.v index 98c12d6b34..c5bd08f9a2 100644 --- a/vlib/orm/orm_test.v +++ b/vlib/orm/orm_test.v @@ -1,55 +1,58 @@ -//import pg - +import pg + struct Modules { - id int - user_id int - name string + id int + user_id int + name string url string - //nr_downloads int + //nr_downloads int } fn test_orm() { -/* - db := pg.connect('vpm', 'alex') - //nr_modules := db.select count from modules - //nr_modules := db.select count from Modules where id == 1 - nr_modules := db.select count from Modules where - name == 'Bob' && id == 1 - println(nr_modules) - - mod := db.select from Modules where id = 1 limit 1 - println(mod) + db := pg.connect( + dbname:'vpm' + user:'alex' + ) +/* + //nr_modules := db.select count from modules + //nr_modules := db.select count from Modules where id == 1 + nr_modules := db.select count from Modules where + name == 'Bob' && id == 1 + println(nr_modules) - mods := db.select from Modules limit 10 - for mod in mods { - println(mod) - } -*/ + mod := db.select from Modules where id = 1 limit 1 + println(mod) -/* - mod := db.retrieve(1) + mods := db.select from Modules limit 10 + for mod in mods { + println(mod) + } +*/ - mod := db.update Module set name = name + '!' where id > 10 +/* + mod := db.retrieve(1) + + mod := db.update Module set name = name + '!' where id > 10 - nr_modules := db.select count from Modules - where id > 1 && name == '' - println(nr_modules) + nr_modules := db.select count from Modules + where id > 1 && name == '' + println(nr_modules) - nr_modules := db.select count from modules - nr_modules := db.select from modules - nr_modules := db[:modules].select -*/ -/* - mod := select from db.modules where id = 1 limit 1 - println(mod.name) - top_mods := select from db.modules where nr_downloads > 1000 order by nr_downloads desc limit 10 - top_mods := db.select from modules where nr_downloads > 1000 order by nr_downloads desc limit 10 - top_mods := db.select(m => m.nr_downloads > 1000).order_by(m => m.nr_downloads).desc().limit(10) - names := select name from db.modules // []string + nr_modules := db.select count from modules + nr_modules := db.select from modules + nr_modules := db[:modules].select +*/ +/* + mod := select from db.modules where id = 1 limit 1 + println(mod.name) + top_mods := select from db.modules where nr_downloads > 1000 order by nr_downloads desc limit 10 + top_mods := db.select from modules where nr_downloads > 1000 order by nr_downloads desc limit 10 + top_mods := db.select(m => m.nr_downloads > 1000).order_by(m => m.nr_downloads).desc().limit(10) + names := select name from db.modules // []string - n := db.q_int('select count(*) from modules') - println(n) -*/ -} + n := db.q_int('select count(*) from modules') + println(n) +*/ +} diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index acbcfbd0de..3b008fba1a 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -87,8 +87,19 @@ fn (mut p Parser) vweb() ast.ComptimeCall { // Compile vweb html template to V code, parse that V code and embed the resulting V function // that returns an html string. mut path := p.cur_fn_name + '.html' - // if p.pref.is_debug { + // if p.pref.is_verbose { println('>>> compiling vweb HTML template "$path"') + // } + if !os.exists(path) { + // Can't find the template file in current directory, + // try looking next to the vweb program, in case it's run with + // v path/to/vweb_app.v + path = os.dir(p.scanner.file_path) + '/' + path + if !os.exists(path) { + p.error('vweb HTML template "$path" not found') + } + // println('path is now "$path"') + } v_code := tmpl.compile_file(path) mut scope := &ast.Scope{ start_pos: 0 @@ -102,17 +113,6 @@ fn (mut p Parser) vweb() ast.ComptimeCall { println('>>> end of vweb template END') println('\n\n') } - /* - if !os.exists(path) { - // Can't find the template file in current directory, - // try looking next to the vweb program, in case it's run with - // v path/to/vweb_app.v - path = os.dir(p.scanner.file_path) + '/' + path - if !os.exists(path) { - p.error('vweb HTML template "$path" not found') - } - } - */ // copy vars from current fn scope into vweb_tmpl scope for stmt in file.stmts { if stmt is ast.FnDecl {