mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: make v test-cleancode
test everything by default (#10050)
This commit is contained in:
@ -55,7 +55,7 @@ pub fn encode_str(data string) string {
|
||||
|
||||
// alloc_and_encode is a private function that allocates and encodes data into a string
|
||||
// Used by encode and encode_str
|
||||
fn alloc_and_encode(src byteptr, len int) string {
|
||||
fn alloc_and_encode(src &byte, len int) string {
|
||||
size := 4 * ((len + 2) / 3)
|
||||
if size <= 0 {
|
||||
return ''
|
||||
@ -107,7 +107,7 @@ pub fn url_encode_str(data string) string {
|
||||
// Please note: The `buffer` should be large enough (i.e. 3/4 of the data.len, or larger)
|
||||
// to hold the decoded data.
|
||||
// Please note: This function does NOT allocate new memory, and is thus suitable for handling very large strings.
|
||||
pub fn decode_in_buffer(data &string, buffer byteptr) int {
|
||||
pub fn decode_in_buffer(data &string, buffer &byte) int {
|
||||
mut padding := 0
|
||||
if data.ends_with('=') {
|
||||
if data.ends_with('==') {
|
||||
@ -125,8 +125,8 @@ pub fn decode_in_buffer(data &string, buffer byteptr) int {
|
||||
mut b := &byte(0)
|
||||
mut d := &byte(0)
|
||||
unsafe {
|
||||
d = byteptr(data.str)
|
||||
b = byteptr(buffer)
|
||||
d = &byte(data.str)
|
||||
b = &byte(buffer)
|
||||
}
|
||||
for i < input_length {
|
||||
mut char_a := 0
|
||||
@ -165,7 +165,7 @@ pub fn decode_in_buffer(data &string, buffer byteptr) int {
|
||||
// encode_in_buffer returns the size of the encoded data in the buffer.
|
||||
// Please note: The buffer should be large enough (i.e. 4/3 of the data.len, or larger) to hold the encoded data.
|
||||
// Please note: The function does NOT allocate new memory, and is suitable for handling very large strings.
|
||||
pub fn encode_in_buffer(data []byte, buffer byteptr) int {
|
||||
pub fn encode_in_buffer(data []byte, buffer &byte) int {
|
||||
return encode_from_buffer(buffer, data.data, data.len)
|
||||
}
|
||||
|
||||
@ -173,16 +173,16 @@ pub fn encode_in_buffer(data []byte, buffer byteptr) int {
|
||||
// and write the bytes into `dest`.
|
||||
// Please note: The `dest` buffer should be large enough (i.e. 4/3 of the src_len, or larger) to hold the encoded data.
|
||||
// Please note: This function is for internal base64 encoding
|
||||
fn encode_from_buffer(dest byteptr, src byteptr, src_len int) int {
|
||||
fn encode_from_buffer(dest &byte, src &byte, src_len int) int {
|
||||
input_length := src_len
|
||||
output_length := 4 * ((input_length + 2) / 3)
|
||||
|
||||
mut i := 0
|
||||
mut j := 0
|
||||
|
||||
mut d := src
|
||||
mut b := dest
|
||||
mut etable := byteptr(base64.enc_table.str)
|
||||
mut d := unsafe { src }
|
||||
mut b := unsafe { dest }
|
||||
mut etable := base64.enc_table.str
|
||||
for i < input_length {
|
||||
mut octet_a := 0
|
||||
mut octet_b := 0
|
||||
|
@ -6,12 +6,11 @@ struct TestPair {
|
||||
}
|
||||
|
||||
const (
|
||||
pairs = [
|
||||
pairs = [
|
||||
// RFC 3548 examples
|
||||
TestPair{'\x14\xfb\x9c\x03\xd9\x7e', 'FPucA9l+'},
|
||||
TestPair{'\x14\xfb\x9c\x03\xd9', 'FPucA9k='},
|
||||
TestPair{'\x14\xfb\x9c\x03', 'FPucAw=='},
|
||||
|
||||
// RFC 4648 examples
|
||||
TestPair{'', ''},
|
||||
TestPair{'f', 'Zg=='},
|
||||
@ -20,7 +19,6 @@ const (
|
||||
TestPair{'foob', 'Zm9vYg=='},
|
||||
TestPair{'fooba', 'Zm9vYmE='},
|
||||
TestPair{'foobar', 'Zm9vYmFy'},
|
||||
|
||||
// Wikipedia examples
|
||||
TestPair{'sure.', 'c3VyZS4='},
|
||||
TestPair{'sure', 'c3VyZQ=='},
|
||||
@ -32,11 +30,7 @@ const (
|
||||
TestPair{'sure.', 'c3VyZS4='},
|
||||
]
|
||||
|
||||
man_pair = TestPair{
|
||||
'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.',
|
||||
'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4='
|
||||
}
|
||||
|
||||
man_pair = TestPair{'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.', 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4='}
|
||||
)
|
||||
|
||||
fn test_decode() {
|
||||
@ -50,7 +44,7 @@ fn test_decode() {
|
||||
for i, p in pairs {
|
||||
got := base64.decode(p.encoded)
|
||||
if got != p.decoded.bytes() {
|
||||
eprintln('pairs[${i}]: expected = ${p.decoded}, got = ${got}')
|
||||
eprintln('pairs[$i]: expected = $p.decoded, got = $got')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
@ -67,7 +61,7 @@ fn test_decode_str() {
|
||||
for i, p in pairs {
|
||||
got := base64.decode_str(p.encoded)
|
||||
if got != p.decoded {
|
||||
eprintln('pairs[${i}]: expected = ${p.decoded}, got = ${got}')
|
||||
eprintln('pairs[$i]: expected = $p.decoded, got = $got')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
@ -79,7 +73,7 @@ fn test_encode() {
|
||||
for i, p in pairs {
|
||||
got := base64.encode(p.decoded.bytes())
|
||||
if got != p.encoded {
|
||||
eprintln('pairs[${i}]: expected = ${p.encoded}, got = ${got}')
|
||||
eprintln('pairs[$i]: expected = $p.encoded, got = $got')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
@ -91,7 +85,7 @@ fn test_encode_str() {
|
||||
for i, p in pairs {
|
||||
got := base64.encode_str(p.decoded)
|
||||
if got != p.encoded {
|
||||
eprintln('pairs[${i}]: expected = ${p.encoded}, got = ${got}')
|
||||
eprintln('pairs[$i]: expected = $p.encoded, got = $got')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
@ -108,31 +102,31 @@ fn test_url_encode_str() {
|
||||
}
|
||||
|
||||
fn test_url_decode() {
|
||||
test := base64.url_decode("SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ")
|
||||
test := base64.url_decode('SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ')
|
||||
assert test == 'Hello Base64Url encoding!'.bytes()
|
||||
}
|
||||
|
||||
fn test_url_decode_str() {
|
||||
test := base64.url_decode_str("SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ")
|
||||
test := base64.url_decode_str('SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ')
|
||||
assert test == 'Hello Base64Url encoding!'
|
||||
}
|
||||
|
||||
fn test_encode_null_byte() {
|
||||
assert base64.encode([byte(`A`) 0 `C`]) == 'QQBD'
|
||||
assert base64.encode([byte(`A`), 0, `C`]) == 'QQBD'
|
||||
}
|
||||
|
||||
fn test_encode_null_byte_str() {
|
||||
// While this works, bytestr() does a memcpy
|
||||
s := [byte(`A`) 0 `C`].bytestr()
|
||||
s := [byte(`A`), 0, `C`].bytestr()
|
||||
assert base64.encode_str(s) == 'QQBD'
|
||||
}
|
||||
|
||||
fn test_decode_null_byte() {
|
||||
assert base64.decode('QQBD') == [byte(`A`) 0 `C`]
|
||||
assert base64.decode('QQBD') == [byte(`A`), 0, `C`]
|
||||
}
|
||||
|
||||
fn test_decode_null_byte_str() {
|
||||
// While this works, bytestr() does a memcpy
|
||||
s := [byte(`A`) 0 `C`].bytestr()
|
||||
s := [byte(`A`), 0, `C`].bytestr()
|
||||
assert base64.decode_str('QQBD') == s
|
||||
}
|
||||
|
Reference in New Issue
Block a user