Added tests for std::fs::path::bits

parent 977f0740
Pipeline #104668024 passed with stages
in 52 minutes and 12 seconds
......@@ -33,6 +33,10 @@ let COLON_BYTE = 58
def starts_with_windows_drive_name?(path: String) -> Boolean {
let first_byte = path.byte(index: 0)
(path.length < 3).if_true {
return False
}
WINDOWS_LOWER_DRIVE_LETTERS.cover?(first_byte)
.or { WINDOWS_UPPER_DRIVE_LETTERS.cover?(first_byte) }
.and { path.byte(index: 1) == COLON_BYTE }
......
......@@ -9,10 +9,11 @@ import test::std::compiler::test_parser
import test::std::compiler::test_source_location
import test::std::compiler::test_token
import test::std::ffi::test_types
import test::std::fs::path::test_bits::(self as _)
import test::std::fs::test_bits::(self as _)
import test::std::fs::test_dir
import test::std::fs::test_file
import test::std::fs::test_path
import test::std::fs::test_bits::(self as _)
import test::std::net::test_ip
import test::std::net::test_socket
import test::std::net::test_unix
......
import std::fs::path::bits::(self, SEPARATOR, SEPARATOR_BYTE, ALT_SEPARATOR_BYTE)
import std::os
import std::test
import std::test::assert
os.windows?.if_true {
test.group('std::fs::path::bits.starts_with_windows_drive_name?') do (g) {
g.test('Checking if a path starts with a Windows drive name') {
assert.true(bits.starts_with_windows_drive_name?('C:/'))
assert.true(bits.starts_with_windows_drive_name?('C:\\'))
assert.false(bits.starts_with_windows_drive_name?('C:'))
assert.false(bits.starts_with_windows_drive_name?('C/'))
assert.false(bits.starts_with_windows_drive_name?('C\\'))
}
}
}
test.group('std::fs::path::bits.path_separator?') do (g) {
g.test('Checking if a byte is a valid path separator') {
assert.true(bits.path_separator?(SEPARATOR_BYTE))
ALT_SEPARATOR_BYTE.negative?.if_false {
assert.true(bits.path_separator?(ALT_SEPARATOR_BYTE))
}
}
}
test.group('std::fs::path::bits.bytes_before_last_separator') do (g) {
g.test('Obtaining the number of bytes without a path separator') {
assert.equal(bits.bytes_before_last_separator('foo'), -1)
}
g.test('Obtaining the number of bytes with a path separator') {
let path = 'foo' + SEPARATOR + 'bar'
assert.equal(bits.bytes_before_last_separator(path), 3)
}
g.test('Obtaining the number of bytes with a trailing path separator') {
let path = 'foo' + SEPARATOR + 'bar' + SEPARATOR
assert.equal(bits.bytes_before_last_separator(path), 3)
}
g.test('Obtaining the number of bytes with a leading path separator') {
let path = SEPARATOR + 'bar' + SEPARATOR
assert.equal(bits.bytes_before_last_separator(path), 1)
}
g.test('Obtaining the number of bytes with multiple path separators') {
let path = SEPARATOR + 'bar' + SEPARATOR + SEPARATOR
assert.equal(bits.bytes_before_last_separator(path), 1)
}
os.windows?.if_true {
g.test('Obtaining the number of bytes using a Windows drive name') {
assert.equal(bits.bytes_before_last_separator('C:/foo'), 3)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment