-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.jl
48 lines (38 loc) · 1.42 KB
/
tests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
include("./Bx/src/algorithm.jl")
using .algorithm
using Test
using Gumbo
TEST_FILE_LOCATION::String = "test_htmls/"
function test_e2e_generate(file_name::String, tagName::String)::Symbol
a = open("$TEST_FILE_LOCATION$file_name.html") do file
read(file, String)
end
document = parsehtml(a)
ruleRoot::algorithm.BxRule = algorithm.generateExtractionRules(document, tagName)
rule = ruleRoot
while rule.next !== nothing
rule = rule.next
end
return rule.nodeSymbol
end
function test_e2e_exe(file_name::String, tagName::String)::String
untagged = open("$TEST_FILE_LOCATION$file_name.html") do file
read(file, String)
end
tagged = open(TEST_FILE_LOCATION * file_name * "_tagged.html") do file
read(file, String)
end
tagged_document = parsehtml(tagged)
untagged_document = parsehtml(untagged)
ruleRoot::algorithm.BxRule = algorithm.generateExtractionRules(tagged_document, tagName)
text = algorithm.executeRule(ruleRoot, untagged_document, tagName)
return text
end
@testset "Bx e2e rule generation tests" begin
@test test_e2e_generate("mini_tagged", "world") == Symbol("bx-tag")
@test test_e2e_generate("ecomm_tagged", "privPolicy") == Symbol("bx-tag")
end
@testset "Bx e2e rule execution tests" begin
@test test_e2e_exe("mini", "world") == "world"
@test test_e2e_exe("ecomm", "privPolicy") == "Browser Extension Privacy Policy"
end