-
Notifications
You must be signed in to change notification settings - Fork 2
/
xhtml_file_spec.rb
executable file
·126 lines (100 loc) · 3.41 KB
/
xhtml_file_spec.rb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# encoding: utf-8
require_relative '../../../spec_helper'
require 'epuber/book'
require 'epuber/compiler'
require 'epuber/compiler/file_types/xhtml_file'
module Epuber
class Compiler
module FileTypes
describe XHTMLFile do
include FakeFS::SpecHelpers
before do
@book = Book.new
@ctx = CompilationContext.new(@book, @book.default_target)
@ctx.file_resolver = FileResolver.new('/', '/.build')
end
it 'handles ugly file with all xml bullshit lines' do
source = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title/>
<meta charset="utf-8"/>
</head>
<body id="Nastaveni-mysli_001-az-304-1">
<div class="_idGenObjectStyleOverride-1">
<p>Some bullshit content</p>
</div>
</body>
</html>
'
File.write('some_file.xhtml', source)
file = XHTMLFile.new('some_file.xhtml')
file.destination_path = 'some_file_dest.xhtml'
resolve_file_paths(file)
file.process(@ctx)
expect(File.read('some_file_dest.xhtml')).to eq source
end
it 'handles xml header on next line' do
source = '
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title/>
<meta charset="utf-8"/>
</head>
<body id="Nastaveni-mysli_001-az-304-1">
<div class="_idGenObjectStyleOverride-1">
<p>Some bullshit content</p>
</div>
</body>
</html>
'
File.write('some_file.xhtml', source)
file = XHTMLFile.new('some_file.xhtml')
file.destination_path = 'some_file_dest.xhtml'
resolve_file_paths(file)
expect {
file.process(@ctx)
}.to output('XML header must be at the beginning of document
(in file some_file.xhtml line 1)'.ansi.yellow + "\n").to_stdout
expect(File.read('some_file_dest.xhtml')).to eq source.lstrip # lstrip is to remove white characters at beginning
end
it 'prints warning when XML is not alright while building release build' do
source = <<~XML
<body>
<p>abc
</body>
XML
File.write('some_file.xhtml', source)
file = XHTMLFile.new('some_file.xhtml')
file.destination_path = 'some_file_dest.xhtml'
resolve_file_paths(file)
@ctx.release_build = true
file.compilation_context = @ctx
expected_output = [
[
'some_file.xhtml:3 column: 8 --- 3:8: FATAL: Opening and ending tag mismatch: p line 2 and body',
' </body>',
' ^',
].join("\n").ansi.yellow,
[
'some_file.xhtml:4 column: 8 --- 4:8: FATAL: Opening and ending tag mismatch: body line 1 and root',
' </body>',
' ^',
].join("\n").ansi.yellow,
[
"some_file.xhtml:4 column: 8 --- 4:8: FATAL: EndTag: '</' not found",
' </body>',
' ^',
].join("\n").ansi.yellow,
].join("\n") + "\n"
expect {
file.process(@ctx)
}.to output(expected_output).to_stdout
end
end
end
end
end