react-native-jet-markdown 0.2.2 → 0.2.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,260 +0,0 @@
1
- // Golden tests for the shared markdown core.
2
- // Build & run: cpp/tests/run_tests.sh
3
-
4
- #include <algorithm>
5
- #include <cstdio>
6
- #include <string>
7
- #include <utility>
8
- #include <vector>
9
-
10
- #include "../core/AstJson.h"
11
- #include "../core/Parser.h"
12
-
13
- namespace {
14
-
15
- int g_failures = 0;
16
- int g_total = 0;
17
-
18
- void expectAst(const char* name, const std::string& markdown, const std::string& expected) {
19
- g_total++;
20
- auto doc = jetmarkdown::parseMarkdown(markdown);
21
- const std::string actual = jetmarkdown::astToJson(doc->root);
22
- if (actual != expected) {
23
- g_failures++;
24
- std::printf("FAIL %s\n input: %s\n expected: %s\n actual: %s\n",
25
- name, markdown.c_str(), expected.c_str(), actual.c_str());
26
- }
27
- }
28
-
29
- void expectContains(const char* name, const std::string& markdown, const std::string& fragment) {
30
- g_total++;
31
- auto doc = jetmarkdown::parseMarkdown(markdown);
32
- const std::string actual = jetmarkdown::astToJson(doc->root);
33
- if (actual.find(fragment) == std::string::npos) {
34
- g_failures++;
35
- std::printf("FAIL %s\n input: %s\n missing: %s\n actual: %s\n",
36
- name, markdown.c_str(), fragment.c_str(), actual.c_str());
37
- }
38
- }
39
-
40
- void expectNotContains(const char* name, const std::string& markdown, const std::string& fragment) {
41
- g_total++;
42
- auto doc = jetmarkdown::parseMarkdown(markdown);
43
- const std::string actual = jetmarkdown::astToJson(doc->root);
44
- if (actual.find(fragment) != std::string::npos) {
45
- g_failures++;
46
- std::printf("FAIL %s\n input: %s\n found unexpected: %s\n actual: %s\n",
47
- name, markdown.c_str(), fragment.c_str(), actual.c_str());
48
- }
49
- }
50
-
51
- } // namespace
52
-
53
- int main() {
54
- using namespace std::string_literals;
55
-
56
- // --- Basics ---
57
- expectAst(
58
- "paragraph",
59
- "hello world",
60
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"hello world"}]}]})");
61
-
62
- expectAst(
63
- "heading",
64
- "## Title",
65
- R"({"type":"document","children":[{"type":"heading","level":2,"children":[{"type":"text","text":"Title"}]}]})");
66
-
67
- expectAst(
68
- "bold italic nesting",
69
- "**bold _italic_**",
70
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"bold","children":[{"type":"text","text":"bold "},{"type":"italic","children":[{"type":"text","text":"italic"}]}]}]}]})");
71
-
72
- expectAst(
73
- "link",
74
- "[label](https://example.com)",
75
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"link","url":"https://example.com","children":[{"type":"text","text":"label"}]}]}]})");
76
-
77
- expectContains(
78
- "mention link keeps scheme",
79
- "hey [@ali](users://ali)!",
80
- R"({"type":"link","url":"users://ali","children":[{"type":"text","text":"@ali"}]})");
81
-
82
- expectContains(
83
- "autolink",
84
- "see https://example.com now",
85
- R"("type":"link","url":"https://example.com")");
86
-
87
- expectAst(
88
- "image",
89
- "![alt text](https://example.com/x.png)",
90
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"image","text":"alt text","url":"https://example.com/x.png"}]}]})");
91
-
92
- expectAst(
93
- "inline code",
94
- "run `npm i` now",
95
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"run "},{"type":"inlineCode","text":"npm i"},{"type":"text","text":" now"}]}]})");
96
-
97
- expectAst(
98
- "code block with lang",
99
- "```js\nlet x = 1;\n```",
100
- R"({"type":"document","children":[{"type":"codeBlock","text":"let x = 1;\n","url":"js"}]})");
101
-
102
- expectContains("block quote", "> quoted", R"("type":"blockQuote")");
103
-
104
- expectContains(
105
- "ordered list start",
106
- "3. three\n4. four",
107
- R"("type":"list","ordered":true,"start":3)");
108
-
109
- expectContains("thematic break", "a\n\n---\n\nb", R"("type":"thematicBreak")");
110
-
111
- expectContains("hard break", "line one \nline two", R"("type":"hardBreak")");
112
-
113
- // --- Tables ---
114
- expectAst(
115
- "table structure",
116
- "| a | b |\n|---|--:|\n| 1 | 2 |",
117
- R"({"type":"document","children":[{"type":"table","children":[{"type":"tableRow","level":1,"children":[{"type":"tableCell","children":[{"type":"text","text":"a"}]},{"type":"tableCell","level":3,"children":[{"type":"text","text":"b"}]}]},{"type":"tableRow","children":[{"type":"tableCell","children":[{"type":"text","text":"1"}]},{"type":"tableCell","level":3,"children":[{"type":"text","text":"2"}]}]}]}]})");
118
-
119
- // --- Spoilers ---
120
- expectAst(
121
- "discord spoiler",
122
- "a ||secret|| b",
123
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"a "},{"type":"spoiler","children":[{"type":"text","text":"secret"}]},{"type":"text","text":" b"}]}]})");
124
-
125
- expectAst(
126
- "reddit spoiler mid-line",
127
- "a >!secret!< b",
128
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"a "},{"type":"spoiler","children":[{"type":"text","text":"secret"}]},{"type":"text","text":" b"}]}]})");
129
-
130
- expectAst(
131
- "reddit spoiler at line start (not blockquote)",
132
- ">!secret!< after",
133
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"spoiler","children":[{"type":"text","text":"secret"}]},{"type":"text","text":" after"}]}]})");
134
-
135
- expectContains(
136
- "spoiler inside blockquote",
137
- "> before >!secret!< after",
138
- R"({"type":"spoiler","children":[{"type":"text","text":"secret"}]})");
139
-
140
- expectAst(
141
- "spoiler spanning styled runs",
142
- "||bold **x** end||",
143
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"spoiler","children":[{"type":"text","text":"bold "},{"type":"bold","children":[{"type":"text","text":"x"}]},{"type":"text","text":" end"}]}]}]})");
144
-
145
- expectNotContains(
146
- "spoiler not inside fenced code",
147
- "```\n>!not a spoiler!<\n||also not||\n```",
148
- R"("type":"spoiler")");
149
-
150
- expectNotContains(
151
- "spoiler not inside inline code",
152
- "`||nope||`",
153
- R"("type":"spoiler")");
154
-
155
- expectNotContains("empty spoiler literal", "||||", R"("type":"spoiler")");
156
-
157
- expectNotContains(
158
- "unclosed spoiler literal",
159
- "a ||secret forever",
160
- R"("type":"spoiler")");
161
-
162
- // --- Strikethrough vs subscript ---
163
- expectAst(
164
- "double tilde strikethrough",
165
- "~~gone~~",
166
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"strikethrough","children":[{"type":"text","text":"gone"}]}]}]})");
167
-
168
- expectAst(
169
- "single tilde subscript",
170
- "H~2~O",
171
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"H"},{"type":"subscript","children":[{"type":"text","text":"2"}]},{"type":"text","text":"O"}]}]})");
172
-
173
- expectNotContains(
174
- "subscript rejects spaces",
175
- "~not a sub~",
176
- R"("type":"subscript")");
177
-
178
- expectContains(
179
- "strikethrough spanning styled runs",
180
- "~~a **b** c~~",
181
- R"({"type":"strikethrough","children":[{"type":"text","text":"a "},{"type":"bold","children":[{"type":"text","text":"b"}]},{"type":"text","text":" c"}]})");
182
-
183
- // --- Superscript ---
184
- expectAst(
185
- "pandoc superscript",
186
- "x^2^ y",
187
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"x"},{"type":"superscript","children":[{"type":"text","text":"2"}]},{"type":"text","text":" y"}]}]})");
188
-
189
- expectAst(
190
- "reddit bare superscript",
191
- "x^2 y",
192
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"x"},{"type":"superscript","children":[{"type":"text","text":"2"}]},{"type":"text","text":" y"}]}]})");
193
-
194
- expectAst(
195
- "reddit paren superscript",
196
- "note^(multi word here) end",
197
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"note"},{"type":"superscript","children":[{"type":"text","text":"multi word here"}]},{"type":"text","text":" end"}]}]})");
198
-
199
- expectAst(
200
- "bare superscript to end of line",
201
- "wow^amazing",
202
- R"({"type":"document","children":[{"type":"paragraph","children":[{"type":"text","text":"wow"},{"type":"superscript","children":[{"type":"text","text":"amazing"}]}]}]})");
203
-
204
- expectNotContains(
205
- "lone caret literal",
206
- "a ^ b",
207
- R"("type":"superscript")");
208
-
209
- // --- Interactions ---
210
- expectContains(
211
- "sub inside spoiler",
212
- "||H~2~O||",
213
- R"({"type":"spoiler","children":[{"type":"text","text":"H"},{"type":"subscript","children":[{"type":"text","text":"2"}]},{"type":"text","text":"O"}]})");
214
-
215
- expectNotContains(
216
- "extensions skip link labels",
217
- "[a ||b|| c](https://example.com)",
218
- R"("type":"spoiler")");
219
-
220
- expectContains(
221
- "entity translation",
222
- "a &amp; b &#65;",
223
- R"({"type":"text","text":"a & b A"})");
224
-
225
- expectContains(
226
- "nested list structure",
227
- "- a\n - b",
228
- R"("type":"list")");
229
-
230
- // --- Hostile nesting must parse without blowing the stack (depth cap).
231
- {
232
- std::string hostile;
233
- for (int i = 0; i < 20000; i++) {
234
- hostile += '>';
235
- }
236
- hostile += " x";
237
- auto doc = jetmarkdown::parseMarkdown(hostile);
238
- g_total++;
239
- if (doc->root == nullptr) {
240
- g_failures++;
241
- std::printf("FAIL deep nesting parse\n");
242
- }
243
- }
244
-
245
- // --- Nested image inside alt text keeps the outer alt intact.
246
- expectContains(
247
- "nested image alt",
248
- "![a ![b](u2) c](u1)",
249
- R"("text":"a b c")");
250
-
251
- // --- Surrogate-range character references become U+FFFD, not invalid
252
- // UTF-8.
253
- expectContains(
254
- "surrogate entity replaced",
255
- "bad &#xD800; ref",
256
- "\xEF\xBF\xBD");
257
-
258
- std::printf("%d/%d passed\n", g_total - g_failures, g_total);
259
- return g_failures == 0 ? 0 : 1;
260
- }
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Builds and runs the shared-core golden tests.
3
- set -euo pipefail
4
-
5
- cd "$(dirname "$0")"
6
-
7
- BUILD_DIR="${TMPDIR:-/tmp}/jetmarkdown-tests"
8
- mkdir -p "$BUILD_DIR"
9
-
10
- clang -c -O1 -o "$BUILD_DIR/md4c.o" ../md4c/md4c.c
11
-
12
- clang++ -std=c++17 -O1 -Wall -Wextra \
13
- -o "$BUILD_DIR/parser_tests" \
14
- parser_tests.cpp \
15
- ../core/Parser.cpp \
16
- ../core/Preprocess.cpp \
17
- ../core/InlineExtensions.cpp \
18
- ../core/AstJson.cpp \
19
- ../core/AstSerializer.cpp \
20
- "$BUILD_DIR/md4c.o"
21
-
22
- "$BUILD_DIR/parser_tests"