annotate scripts/test.luan @ 500:ab9c2afefb47

add response.binary_writer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 May 2015 20:59:30 -0600
parents 55f9f74f1e55
children 92c3d22745b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
1 local Luan = require "luan:Luan"
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
2 local error = Luan.error
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
3 local range = Luan.range
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
4 local Io = require "luan:Io"
494
2b9bc97f0439 change luan:web to luan:http
Franklin Schmidt <fschmidt@gmail.com>
parents: 435
diff changeset
5 local Http = require "luan:http/Http"
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
6 local init_for_test = Http.init_for_test
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
7 local Lucene = require "luan:lucene/Lucene"
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
8 local Ab_testing = require "luan:lucene/Ab_testing"
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
9
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
10
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
11 local function print(...)
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
12 Io.print_to(Io.stderr,...)
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
13 end
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
14
495
598123096772 rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents: 494
diff changeset
15 function Io.schemes.site(path,add_extension)
598123096772 rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents: 494
diff changeset
16 return Io.uri( "luan:http"..path, add_extension )
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
17 end
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
18
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
19
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
20 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
21 Http.request.parameter.code = "require('luan:Io').print 'hi'"
435
5b36f663a1b8 make members lower case
Franklin Schmidt <fschmidt@gmail.com>
parents: 323
diff changeset
22 page = Http.get_page "/run"
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
23 page.trim() == "hi" or error "failed"
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
24
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
25 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
26 Http.request.parameter.cmd = "'ab'..'cd'"
435
5b36f663a1b8 make members lower case
Franklin Schmidt <fschmidt@gmail.com>
parents: 323
diff changeset
27 page = Http.get_page "/shell"
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
28 page.find "abcd" or error "failed"
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
29
321
7f7708e8fdd4 remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 308
diff changeset
30
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
31 -- lucene
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
32
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
33 this_file = Io.schemes.file(Luan.arg[0])
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
34 this_dir = this_file.parent()
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
35 lucene_dir = this_dir.parent().child("build").child("lucene_test")
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
36 --print(lucene_dir.to_string())
435
5b36f663a1b8 make members lower case
Franklin Schmidt <fschmidt@gmail.com>
parents: 323
diff changeset
37 db = Lucene.index(lucene_dir.to_string())
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
38 db.delete_all()
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
39
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
40 ab_testing = Ab_testing.of(db)
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
41 test_events = {"all"}
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
42 aggregator_factories = {
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
43 all = Ab_testing.count_all;
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
44 }
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
45 ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
46 ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories }
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
47
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
48 for record in range(1,10) do
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
49 local doc = {type="test"}
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
50 ab_testing.to_doc(doc)
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
51 db.save_document(doc)
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
52 end
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
53
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
54 init_for_test()
495
598123096772 rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents: 494
diff changeset
55 ab_testing.web_page{"All","null"}.respond()
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
56
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
57 local Web_search = require "luan:lucene/Web_search"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
58 local web_search = Web_search.of(db)
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
59
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
60 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
61 web_search.respond()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
62
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
63 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
64 Http.request.parameter.query = "Query.all_docs"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
65 Http.request.parameter.rows = "100"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
66 Http.request.parameter.sort = ""
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
67 web_search.respond()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
68
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
69
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
70 -- website
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
71
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
72 function Io.schemes.site(path,add_extension)
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
73 return Io.uri( "file:../website/src"..path, add_extension )
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
74 end
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
75
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
76 init_for_test(); Http.get_page "/"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
77 init_for_test(); Http.get_page "/docs.html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
78 init_for_test(); Http.get_page "/tutorial.html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
79 init_for_test(); Http.get_page "/pil.html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
80 init_for_test(); Http.get_page "/manual.html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
81 init_for_test(); Http.get_page "/diff.html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
82 init_for_test(); Http.get_page "/examples/hi"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
83 init_for_test(); Http.get_page "/examples/hi2"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
84 init_for_test(); Http.get_page "/examples/hi2_simply_html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
85 init_for_test(); Http.get_page "/examples/shell"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
86
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
87 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
88 Http.request.parameter.name = "bob"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
89 page = Http.get_page "/examples/hi2"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
90 page.find "bob" or error "failed"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
91
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
92 init_for_test()
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
93 Http.request.parameter.name = "bob"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
94 page = Http.get_page "/examples/hi2_simply_html"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
95 page.find "bob" or error "failed"
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
96
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
97
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 321
diff changeset
98 print "done"