comparison scripts/test.luan @ 497:55f9f74f1e55

Http.request is now pure luan
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 17 May 2015 19:25:47 -0600
parents 598123096772
children 92c3d22745b8
comparison
equal deleted inserted replaced
496:c65df5b25932 497:55f9f74f1e55
1 local Luan = require "luan:Luan" 1 local Luan = require "luan:Luan"
2 local assert = Luan.assert 2 local error = Luan.error
3 local range = Luan.range 3 local range = Luan.range
4 local Io = require "luan:Io" 4 local Io = require "luan:Io"
5 local Http = require "luan:http/Http" 5 local Http = require "luan:http/Http"
6 local init_for_test = Http.init_for_test
6 local Lucene = require "luan:lucene/Lucene" 7 local Lucene = require "luan:lucene/Lucene"
7 local Ab_testing = require "luan:lucene/Ab_testing" 8 local Ab_testing = require "luan:lucene/Ab_testing"
8 9
9 10
10 local function print(...) 11 local function print(...)
14 function Io.schemes.site(path,add_extension) 15 function Io.schemes.site(path,add_extension)
15 return Io.uri( "luan:http"..path, add_extension ) 16 return Io.uri( "luan:http"..path, add_extension )
16 end 17 end
17 18
18 19
19 Http.init_for_test() 20 init_for_test()
20 Http.request.parameters.code = "require('luan:Io').print 'hi'" 21 Http.request.parameter.code = "require('luan:Io').print 'hi'"
21 page = Http.get_page "/run" 22 page = Http.get_page "/run"
22 assert( page.trim() == "hi" ) 23 page.trim() == "hi" or error "failed"
23 24
24 Http.init_for_test() 25 init_for_test()
25 Http.request.parameters.cmd = "'ab'..'cd'" 26 Http.request.parameter.cmd = "'ab'..'cd'"
26 page = Http.get_page "/shell" 27 page = Http.get_page "/shell"
27 assert( page.find "abcd" ) 28 page.find "abcd" or error "failed"
28 29
29 30
30 -- lucene 31 -- lucene
31 32
32 this_file = Io.schemes.file(Luan.arg[0]) 33 this_file = Io.schemes.file(Luan.arg[0])
48 local doc = {type="test"} 49 local doc = {type="test"}
49 ab_testing.to_doc(doc) 50 ab_testing.to_doc(doc)
50 db.save_document(doc) 51 db.save_document(doc)
51 end 52 end
52 53
53 Http.init_for_test() 54 init_for_test()
54 ab_testing.web_page{"All","null"}.respond() 55 ab_testing.web_page{"All","null"}.respond()
56
57 local Web_search = require "luan:lucene/Web_search"
58 local web_search = Web_search.of(db)
59
60 init_for_test()
61 web_search.respond()
62
63 init_for_test()
64 Http.request.parameter.query = "Query.all_docs"
65 Http.request.parameter.rows = "100"
66 Http.request.parameter.sort = ""
67 web_search.respond()
68
69
70 -- website
71
72 function Io.schemes.site(path,add_extension)
73 return Io.uri( "file:../website/src"..path, add_extension )
74 end
75
76 init_for_test(); Http.get_page "/"
77 init_for_test(); Http.get_page "/docs.html"
78 init_for_test(); Http.get_page "/tutorial.html"
79 init_for_test(); Http.get_page "/pil.html"
80 init_for_test(); Http.get_page "/manual.html"
81 init_for_test(); Http.get_page "/diff.html"
82 init_for_test(); Http.get_page "/examples/hi"
83 init_for_test(); Http.get_page "/examples/hi2"
84 init_for_test(); Http.get_page "/examples/hi2_simply_html"
85 init_for_test(); Http.get_page "/examples/shell"
86
87 init_for_test()
88 Http.request.parameter.name = "bob"
89 page = Http.get_page "/examples/hi2"
90 page.find "bob" or error "failed"
91
92 init_for_test()
93 Http.request.parameter.name = "bob"
94 page = Http.get_page "/examples/hi2_simply_html"
95 page.find "bob" or error "failed"
55 96
56 97
57 print "done" 98 print "done"