Mercurial Hosting > luan
annotate scripts/test.luan @ 523:dcd278f02e67
Added tag 0.9 for changeset a7ea7ff0a726
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 May 2015 03:13:30 -0600 |
parents | 72610ddea6a7 |
children | 473e456444ff |
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" | |
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 |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
21 local range = Luan.range |
506 | 22 local init = Http_test.init |
23 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
|
24 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
|
25 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
26 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
27 local function print(...) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
28 Io.print_to(Io.stderr,...) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
29 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
30 |
495
598123096772
rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents:
494
diff
changeset
|
31 function Io.schemes.site(path,add_extension) |
598123096772
rename service() to respond()
Franklin Schmidt <fschmidt@gmail.com>
parents:
494
diff
changeset
|
32 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
|
33 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
34 |
503 | 35 local page |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
36 |
503 | 37 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
38 Http.request.parameter.code = "require('luan:Io').print 'hi'" |
503 | 39 page = get_page "/run" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
40 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
|
41 |
503 | 42 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
43 Http.request.parameter.cmd = "'ab'..'cd'" |
503 | 44 page = get_page "/shell" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
45 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
|
46 |
507 | 47 init() |
48 page = get_page "/dump" | |
49 | |
321
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
308
diff
changeset
|
50 |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
51 -- lucene |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
52 |
503 | 53 local this_file = Io.schemes.file(Luan.arg[0]) |
54 local this_dir = this_file.parent() | |
55 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
|
56 --print(lucene_dir.to_string()) |
503 | 57 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
|
58 db.delete_all() |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
59 |
503 | 60 local ab_testing = Ab_testing.of(db) |
61 local test_events = {"all"} | |
62 local aggregator_factories = { | |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
63 all = Ab_testing.count_all; |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
64 } |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
65 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
|
66 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
|
67 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
68 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
|
69 local doc = {type="test"} |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
70 ab_testing.to_doc(doc) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
71 db.save_document(doc) |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
72 end |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
73 |
503 | 74 init() |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
75 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
|
76 |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
77 local Web_search = require "luan:lucene/Web_search" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
78 local web_search = Web_search.of(db) |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
79 |
503 | 80 init() |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
81 web_search() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
82 |
503 | 83 init() |
519 | 84 Http.request.parameter.query = "query.all_docs" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
85 Http.request.parameter.rows = "100" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
86 Http.request.parameter.sort = "" |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
87 web_search() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
88 |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
89 |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
90 -- website |
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 function Io.schemes.site(path,add_extension) |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
93 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
|
94 end |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
95 |
503 | 96 init(); get_page "/" |
97 init(); get_page "/docs.html" | |
98 init(); get_page "/tutorial.html" | |
99 init(); get_page "/pil.html" | |
100 init(); get_page "/manual.html" | |
101 init(); get_page "/diff.html" | |
102 init(); get_page "/examples/hi" | |
103 init(); get_page "/examples/hi2" | |
104 init(); get_page "/examples/hi2_simply_html" | |
105 init(); get_page "/examples/shell" | |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
106 |
503 | 107 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
108 Http.request.parameter.name = "bob" |
503 | 109 page = get_page "/examples/hi2" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
110 page.find "bob" or error "failed" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
111 |
503 | 112 init() |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
113 Http.request.parameter.name = "bob" |
503 | 114 page = get_page "/examples/hi2_simply_html" |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
115 page.find "bob" or error "failed" |
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
116 |
323
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
117 |
cd2924a1052c
improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
321
diff
changeset
|
118 print "done" |