Mercurial Hosting > luan
annotate scripts/test.luan @ 549:c69b4833a3a3
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 15 Jun 2015 18:33:48 -0600 |
parents | f4dfe9c64c25 |
children | 18504c41b0be |
rev | line source |
---|---|
503 | 1 local Binary = require "luan:Binary" |
2 local Debug = require "luan:Debug" | |
3 local Html = require "luan:Html" | |
4 local Io = require "luan:Io" | |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
5 local Luan = require "luan:Luan" |
503 | 6 local Math = require "luan:Math" |
7 local Package = require "luan:Package" | |
8 local String = require "luan:String" | |
9 local Table = require "luan:Table" | |
10 local Thread = require "luan:Thread" | |
11 local Time = require "luan:Time" | |
12 local Hosting = require "luan:host/Hosting" | |
13 local Http = require "luan:http/Http" | |
506 | 14 local Http_test = require "luan:http/Http_test" |
503 | 15 local Server = require "luan:http/Server" |
16 local Lucene = require "luan:lucene/Lucene" | |
548
f4dfe9c64c25
shorten some String function names
Franklin Schmidt <fschmidt@gmail.com>
parents:
547
diff
changeset
|
17 local Versioning = require "luan:lucene/Versioning" |
503 | 18 local Mail = require "luan:mail/Mail" |
19 local Stripe = require "luan:stripe/Stripe" | |
20 | |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
21 local error = Luan.error |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
22 local range = Luan.range |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
23 local trim = String.trim |
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
24 local find = String.find |
506 | 25 local init = Http_test.init |
26 local get_page = Http_test.get_page | |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
27 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
|
28 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
29 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
30 local function print(...) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
31 Io.print_to(Io.stderr,...) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
32 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
33 |
495
598123096772
rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents:
494
diff
changeset
|
34 function Io.schemes.site(path,add_extension) |
598123096772
rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents:
494
diff
changeset
|
35 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
|
36 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
37 |
503 | 38 local page |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
39 |
503 | 40 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
41 Http.request.parameter.code = "require('luan:Io').print 'hi'" |
503 | 42 page = get_page "/run" |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
43 trim(page) == "hi" or error "failed" |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
44 |
503 | 45 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
46 Http.request.parameter.cmd = "'ab'..'cd'" |
503 | 47 page = get_page "/shell" |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
48 find(page,"abcd") or error "failed" |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
49 |
507 | 50 init() |
51 page = get_page "/dump" | |
52 | |
321
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
308
diff
changeset
|
53 |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
54 -- lucene |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
55 |
503 | 56 local this_file = Io.schemes.file(Luan.arg[0]) |
57 local this_dir = this_file.parent() | |
58 local lucene_dir = this_dir.parent().child("build").child("lucene_test") | |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
59 --print(lucene_dir.to_string()) |
503 | 60 local 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
|
61 db.delete_all() |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
62 |
503 | 63 local ab_testing = Ab_testing.of(db) |
64 local test_events = {"all"} | |
65 local aggregator_factories = { | |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
66 all = Ab_testing.count_all; |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
67 } |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
68 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
|
69 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
|
70 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
71 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
|
72 local doc = {type="test"} |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
73 ab_testing.to_doc(doc) |
547
0be287ab0309
add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
74 db.save(doc) |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
75 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
76 |
503 | 77 init() |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
78 ab_testing.web_page{"All","null"}() |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
79 |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
80 local Web_search = require "luan:lucene/Web_search" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
81 local web_search = Web_search.of(db) |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
82 |
503 | 83 init() |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
84 web_search() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
85 |
503 | 86 init() |
544
c5a93767cc5c
lucene overhaul, untested
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
87 Http.request.parameter.query = "" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
88 Http.request.parameter.rows = "100" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
89 Http.request.parameter.sort = "" |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
90 web_search() |
497
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 |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
93 -- website |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
94 |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
95 function Io.schemes.site(path,add_extension) |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
96 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
|
97 end |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
98 |
503 | 99 init(); get_page "/" |
100 init(); get_page "/docs.html" | |
101 init(); get_page "/tutorial.html" | |
102 init(); get_page "/pil.html" | |
103 init(); get_page "/manual.html" | |
104 init(); get_page "/diff.html" | |
105 init(); get_page "/examples/hi" | |
106 init(); get_page "/examples/hi2" | |
107 init(); get_page "/examples/hi2_simply_html" | |
108 init(); get_page "/examples/shell" | |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
109 |
503 | 110 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
111 Http.request.parameter.name = "bob" |
503 | 112 page = get_page "/examples/hi2" |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
113 find(page,"bob") or error "failed" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
114 |
503 | 115 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
116 Http.request.parameter.name = "bob" |
503 | 117 page = get_page "/examples/hi2_simply_html" |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
519
diff
changeset
|
118 find(page,"bob") or error "failed" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
119 |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
120 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
121 print "done" |