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