Skip to content

Commit e75c589

Browse files
feat: URL tests and include them in test runner
1 parent 57e7ee1 commit e75c589

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

src/test/tester.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { runAceCompatibilityTests } from "./ace.test";
22
import { runCodeMirrorTests } from "./editor.tests";
33
import { runExecutorTests } from "./exec.tests";
44
import { runSanityTests } from "./sanity.tests";
5+
import { runUrlTests } from "./url.tests";
56

67
export async function runAllTests() {
78
const terminal = acode.require("terminal");
@@ -20,6 +21,7 @@ export async function runAllTests() {
2021
await runCodeMirrorTests(write);
2122
await runAceCompatibilityTests(write);
2223
await runExecutorTests(write);
24+
await runUrlTests(write);
2325

2426
write("\x1b[36m\x1b[1mTests completed!\x1b[0m\n");
2527
} catch (error) {

src/test/url.tests.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { TestRunner } from "./tester";
2+
import Url from "../utils/Url";
3+
4+
export async function runUrlTests(writeOutput) {
5+
const runner = new TestRunner("URL / SAF URI Tests");
6+
7+
runner.test(
8+
"Android external storage: join active location + index.html",
9+
(test) => {
10+
const folderUrl =
11+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml";
12+
const activeLocation =
13+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml::primary:Testhtml/Styles/";
14+
const expectedJoined =
15+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml::primary:Testhtml/Styles/index.html";
16+
17+
const joined = Url.join(activeLocation, "index.html");
18+
19+
test.assertEqual(
20+
joined,
21+
expectedJoined,
22+
"Joined URL should match expected Android SAF file URI",
23+
);
24+
test.assert(
25+
!Url.areSame(folderUrl, joined),
26+
"Folder URL and joined file URL should not be considered same",
27+
);
28+
},
29+
);
30+
31+
runner.test("Termux SAF: join active location + index.html", (test) => {
32+
const folderUrl =
33+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome%2Facode-site-ui";
34+
const activeLocation =
35+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome%2Facode-site-ui::/data/data/com.termux/files/home/acode-site-ui/";
36+
const expectedJoined =
37+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome%2Facode-site-ui::/data/data/com.termux/files/home/acode-site-ui/index.html";
38+
39+
const joined = Url.join(activeLocation, "index.html");
40+
41+
test.assertEqual(
42+
joined,
43+
expectedJoined,
44+
"Joined URL should match expected Termux SAF file URI",
45+
);
46+
test.assert(
47+
!Url.areSame(folderUrl, joined),
48+
"Folder URL and joined file URL should not be considered same",
49+
);
50+
});
51+
52+
runner.test(
53+
"Acode terminal SAF: join active location + index.html",
54+
(test) => {
55+
const folderUrl =
56+
"content://com.foxdebug.acode.documents/tree/%2Fdata%2Fuser%2F0%2Fcom.foxdebug.acode%2Ffiles%2Fpublic";
57+
const activeLocation =
58+
"content://com.foxdebug.acode.documents/tree/%2Fdata%2Fuser%2F0%2Fcom.foxdebug.acode%2Ffiles%2Fpublic::/data/user/0/com.foxdebug.acode/files/public/";
59+
const expectedJoined =
60+
"content://com.foxdebug.acode.documents/tree/%2Fdata%2Fuser%2F0%2Fcom.foxdebug.acode%2Ffiles%2Fpublic::/data/user/0/com.foxdebug.acode/files/public/index.html";
61+
62+
const joined = Url.join(activeLocation, "index.html");
63+
64+
test.assertEqual(
65+
joined,
66+
expectedJoined,
67+
"Joined URL should match expected Acode Terminal SAF file URI",
68+
);
69+
test.assert(
70+
!Url.areSame(folderUrl, joined),
71+
"Folder URL and joined file URL should not be considered same",
72+
);
73+
},
74+
);
75+
76+
runner.test(
77+
"Android SAF folder URL should match with trailing slash",
78+
(test) => {
79+
const a =
80+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml/";
81+
const b =
82+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml";
83+
84+
test.assert(
85+
Url.areSame(a, b),
86+
"Android folder URLs differing only by trailing slash should be same",
87+
);
88+
},
89+
);
90+
91+
runner.test(
92+
"Termux SAF folder URL should match with trailing slash",
93+
(test) => {
94+
const a =
95+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome%2Facode-site-ui/";
96+
const b =
97+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome%2Facode-site-ui";
98+
99+
test.assert(
100+
Url.areSame(a, b),
101+
"Termux folder URLs differing only by trailing slash should be same",
102+
);
103+
},
104+
);
105+
106+
runner.test(
107+
"Acode terminal SAF folder URL should match with trailing slash",
108+
(test) => {
109+
const a =
110+
"content://com.foxdebug.acode.documents/tree/%2Fdata%2Fuser%2F0%2Fcom.foxdebug.acode%2Ffiles%2Fpublic/";
111+
const b =
112+
"content://com.foxdebug.acode.documents/tree/%2Fdata%2Fuser%2F0%2Fcom.foxdebug.acode%2Ffiles%2Fpublic";
113+
114+
test.assert(
115+
Url.areSame(a, b),
116+
"Acode terminal folder URLs differing only by trailing slash should be same",
117+
);
118+
},
119+
);
120+
121+
runner.test("join should handle leading slash segment", (test) => {
122+
const activeLocation =
123+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml::primary:Testhtml/Styles/";
124+
const expectedJoined =
125+
"content://com.android.externalstorage.documents/tree/primary%3ATesthtml::primary:Testhtml/Styles/index.html";
126+
127+
const joined = Url.join(activeLocation, "/index.html");
128+
test.assertEqual(
129+
joined,
130+
expectedJoined,
131+
"Leading slash in joined segment should be normalized",
132+
);
133+
});
134+
135+
return await runner.run(writeOutput);
136+
}

0 commit comments

Comments
 (0)