-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmbtexcel_demo_sparklines_roundtrip_test.mbt
More file actions
68 lines (62 loc) · 2.42 KB
/
Copy pathmbtexcel_demo_sparklines_roundtrip_test.mbt
File metadata and controls
68 lines (62 loc) · 2.42 KB
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
///|
fn assert_demo_sparklines_archive(bytes : Bytes) -> Unit raise {
let archive = @zip.read(bytes)
inspect(archive.get("xl/worksheets/sheet1.xml") is Some(_), content="true")
inspect(archive.get("xl/sharedStrings.xml") is Some(_), content="true")
inspect(
archive.get("xl/worksheets/_rels/sheet1.xml.rels") is None,
content="true",
)
let workbook_rels = match archive.get("xl/_rels/workbook.xml.rels") {
Some(value) => @encoding/utf8.decode(value)
None => fail("missing workbook rels")
}
let workbook_ids = demo_rel_attr_values(workbook_rels, "Id")
let workbook_targets = demo_rel_attr_values(workbook_rels, "Target")
inspect(demo_unique(workbook_ids), content="true")
inspect(
demo_has_value(workbook_targets, "worksheets/sheet1.xml"),
content="true",
)
inspect(demo_has_value(workbook_targets, "sharedStrings.xml"), content="true")
let sheet_xml = match archive.get("xl/worksheets/sheet1.xml") {
Some(value) => @encoding/utf8.decode(value)
None => fail("missing sheet1 xml")
}
inspect(sheet_xml.contains("mc:Ignorable=\"x14\""), content="true")
inspect(sheet_xml.contains("<x14:sparklineGroups"), content="true")
inspect(sheet_xml.contains("xmlns:xm="), content="true")
inspect(demo_count_tag(sheet_xml, "<x14:sparkline>"), content="4")
inspect(demo_count_tag(sheet_xml, "<xm:f>"), content="4")
inspect(demo_count_tag(sheet_xml, "<xm:sqref>"), content="4")
let content_types = match archive.get("[Content_Types].xml") {
Some(value) => @encoding/utf8.decode(value)
None => fail("missing content types")
}
inspect(
content_types.contains(
"ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"",
),
content="true",
)
inspect(
content_types.contains(
"ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml\"",
),
content="true",
)
}
///|
test "demo sparklines: writer output remains consistent after roundtrip" {
let bytes = @demos.demo_sparklines_bytes()
assert_demo_sparklines_archive(bytes)
let parsed = @mbtexcel.read(bytes)
let kpi = match parsed.sheet("KPI") {
Some(value) => value
None => fail("missing KPI sheet")
}
inspect(kpi.sparkline_groups().length(), content="1")
inspect(kpi.sparkline_groups()[0].sparklines.length(), content="4")
let roundtrip_bytes = @mbtexcel.write(parsed)
assert_demo_sparklines_archive(roundtrip_bytes)
}