Page MenuHomePhorge

test_path.cjs
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

test_path.cjs

import * as path from 'ant:path';
console.log('Testing ant:path module...\n');
// Test 1: path.basename
console.log('=== Test 1: path.basename ===');
let result1 = path.basename('/foo/bar/baz.js');
console.log('basename("/foo/bar/baz.js"):', result1);
if (result1 !== 'baz.js') {
throw new Error('Expected "baz.js" but got: ' + result1);
}
let result2 = path.basename('/foo/bar/baz.js', '.js');
console.log('basename("/foo/bar/baz.js", ".js"):', result2);
if (result2 !== 'baz') {
throw new Error('Expected "baz" but got: ' + result2);
}
// Test 2: path.dirname
console.log('\n=== Test 2: path.dirname ===');
let result3 = path.dirname('/foo/bar/baz.js');
console.log('dirname("/foo/bar/baz.js"):', result3);
if (result3 !== '/foo/bar') {
throw new Error('Expected "/foo/bar" but got: ' + result3);
}
let result4 = path.dirname('/foo');
console.log('dirname("/foo"):', result4);
if (result4 !== '/') {
throw new Error('Expected "/" but got: ' + result4);
}
// Test 3: path.extname
console.log('\n=== Test 3: path.extname ===');
let result5 = path.extname('index.html');
console.log('extname("index.html"):', result5);
if (result5 !== '.html') {
throw new Error('Expected ".html" but got: ' + result5);
}
let result6 = path.extname('index.coffee.md');
console.log('extname("index.coffee.md"):', result6);
if (result6 !== '.md') {
throw new Error('Expected ".md" but got: ' + result6);
}
let result7 = path.extname('index.');
console.log('extname("index."):', result7);
if (result7 !== '.') {
throw new Error('Expected "." but got: ' + result7);
}
let result8 = path.extname('index');
console.log('extname("index"):', result8);
if (result8 !== '') {
throw new Error('Expected "" but got: ' + result8);
}
let result9 = path.extname('.index');
console.log('extname(".index"):', result9);
if (result9 !== '') {
throw new Error('Expected "" but got: ' + result9);
}
// Test 4: path.join
console.log('\n=== Test 4: path.join ===');
let result10 = path.join('/foo', 'bar', 'baz/asdf', 'quux');
console.log('join("/foo", "bar", "baz/asdf", "quux"):', result10);
if (result10 !== '/foo/bar/baz/asdf/quux') {
throw new Error('Expected "/foo/bar/baz/asdf/quux" but got: ' + result10);
}
let result11 = path.join('foo', 'bar', 'baz');
console.log('join("foo", "bar", "baz"):', result11);
if (result11 !== 'foo/bar/baz') {
throw new Error('Expected "foo/bar/baz" but got: ' + result11);
}
// Test 5: path.normalize
console.log('\n=== Test 5: path.normalize ===');
let result12 = path.normalize('/foo/bar//baz/asdf/quux/..');
console.log('normalize("/foo/bar//baz/asdf/quux/.."):', result12);
// Simplified normalize just removes duplicate slashes
if (!result12.includes('/foo/bar/baz')) {
console.log(' Note: Simplified normalization');
}
// Test 6: path.isAbsolute
console.log('\n=== Test 6: path.isAbsolute ===');
let result13 = path.isAbsolute('/foo/bar');
console.log('isAbsolute("/foo/bar"):', result13);
if (result13 !== true) {
throw new Error('Expected true but got: ' + result13);
}
let result14 = path.isAbsolute('foo/bar');
console.log('isAbsolute("foo/bar"):', result14);
if (result14 !== false) {
throw new Error('Expected false but got: ' + result14);
}
let result15 = path.isAbsolute('.');
console.log('isAbsolute("."):', result15);
if (result15 !== false) {
throw new Error('Expected false but got: ' + result15);
}
// Test 7: path.parse
console.log('\n=== Test 7: path.parse ===');
let result16 = path.parse('/home/user/dir/file.txt');
console.log('parse("/home/user/dir/file.txt"):');
console.log(' root:', result16.root);
console.log(' dir:', result16.dir);
console.log(' base:', result16.base);
console.log(' ext:', result16.ext);
console.log(' name:', result16.name);
if (result16.root !== '/') {
throw new Error('Expected root "/" but got: ' + result16.root);
}
if (result16.dir !== '/home/user/dir') {
throw new Error('Expected dir "/home/user/dir" but got: ' + result16.dir);
}
if (result16.base !== 'file.txt') {
throw new Error('Expected base "file.txt" but got: ' + result16.base);
}
if (result16.ext !== '.txt') {
throw new Error('Expected ext ".txt" but got: ' + result16.ext);
}
if (result16.name !== 'file') {
throw new Error('Expected name "file" but got: ' + result16.name);
}
// Test 8: path.format
console.log('\n=== Test 8: path.format ===');
let result17 = path.format({
dir: '/home/user/dir',
base: 'file.txt'
});
console.log('format({dir: "/home/user/dir", base: "file.txt"}):', result17);
if (result17 !== '/home/user/dir/file.txt') {
throw new Error('Expected "/home/user/dir/file.txt" but got: ' + result17);
}
let result18 = path.format({
root: '/ignored',
dir: '/home/user/dir',
name: 'file',
ext: '.txt'
});
console.log('format({root: "/ignored", dir: "/home/user/dir", name: "file", ext: ".txt"}):', result18);
if (result18 !== '/home/user/dir/file.txt') {
throw new Error('Expected "/home/user/dir/file.txt" but got: ' + result18);
}
// Test 9: path.resolve
console.log('\n=== Test 9: path.resolve ===');
let result19 = path.resolve('foo', 'bar', 'baz');
console.log('resolve("foo", "bar", "baz"):', result19);
if (!result19.includes('foo') || !result19.includes('bar') || !result19.includes('baz')) {
throw new Error('Expected resolved path to contain foo/bar/baz');
}
let result20 = path.resolve('/foo', 'bar');
console.log('resolve("/foo", "bar"):', result20);
if (result20 !== '/foo/bar') {
throw new Error('Expected "/foo/bar" but got: ' + result20);
}
// Test 10: Constants
console.log('\n=== Test 10: Constants ===');
console.log('path.sep:', path.sep);
if (path.sep !== '/') {
throw new Error('Expected "/" but got: ' + path.sep);
}
console.log('path.delimiter:', path.delimiter);
if (path.delimiter !== ':') {
throw new Error('Expected ":" but got: ' + path.delimiter);
}
console.log('\n✓ All path tests passed!');

File Metadata

Mime Type
application/javascript
Expires
Fri, Mar 27, 6:15 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512381
Default Alt Text
test_path.cjs (5 KB)

Event Timeline