view 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
line wrap: on
line source

local Luan = require "luan:Luan"
local error = Luan.error
local range = Luan.range
local Io = require "luan:Io"
local Http = require "luan:http/Http"
local init_for_test = Http.init_for_test
local Lucene = require "luan:lucene/Lucene"
local Ab_testing = require "luan:lucene/Ab_testing"


local function print(...)
	Io.print_to(Io.stderr,...)
end

function Io.schemes.site(path,add_extension)
	return Io.uri( "luan:http"..path, add_extension )
end


init_for_test()
Http.request.parameter.code = "require('luan:Io').print 'hi'"
page = Http.get_page "/run"
page.trim() == "hi" or error "failed"

init_for_test()
Http.request.parameter.cmd = "'ab'..'cd'"
page = Http.get_page "/shell"
page.find "abcd" or error "failed"


-- lucene

this_file = Io.schemes.file(Luan.arg[0])
this_dir = this_file.parent()
lucene_dir = this_dir.parent().child("build").child("lucene_test")
--print(lucene_dir.to_string())
db = Lucene.index(lucene_dir.to_string())
db.delete_all()

ab_testing = Ab_testing.of(db)
test_events = {"all"}
aggregator_factories = {
	all = Ab_testing.count_all;
}
ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories }

for record in range(1,10) do
	local doc = {type="test"}
	ab_testing.to_doc(doc)
	db.save_document(doc)
end

init_for_test()
ab_testing.web_page{"All","null"}.respond()

local Web_search = require "luan:lucene/Web_search"
local web_search = Web_search.of(db)

init_for_test()
web_search.respond()

init_for_test()
Http.request.parameter.query = "Query.all_docs"
Http.request.parameter.rows = "100"
Http.request.parameter.sort = ""
web_search.respond()


-- website

function Io.schemes.site(path,add_extension)
	return Io.uri( "file:../website/src"..path, add_extension )
end

init_for_test(); Http.get_page "/"
init_for_test(); Http.get_page "/docs.html"
init_for_test(); Http.get_page "/tutorial.html"
init_for_test(); Http.get_page "/pil.html"
init_for_test(); Http.get_page "/manual.html"
init_for_test(); Http.get_page "/diff.html"
init_for_test(); Http.get_page "/examples/hi"
init_for_test(); Http.get_page "/examples/hi2"
init_for_test(); Http.get_page "/examples/hi2_simply_html"
init_for_test(); Http.get_page "/examples/shell"

init_for_test()
Http.request.parameter.name = "bob"
page = Http.get_page "/examples/hi2"
page.find "bob" or error "failed"

init_for_test()
Http.request.parameter.name = "bob"
page = Http.get_page "/examples/hi2_simply_html"
page.find "bob" or error "failed"


print "done"