mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix octal and hex int literals
This commit is contained in:
parent
ed3e0c43bc
commit
75c2ef7947
@ -99,9 +99,7 @@ fn test_sort() {
|
||||
}
|
||||
|
||||
fn test_split_nth() {
|
||||
|
||||
a := "1,2,3"
|
||||
println(a)
|
||||
assert (a.split(',').len == 3)
|
||||
assert (a.split_nth(',', -1).len == 3)
|
||||
assert (a.split_nth(',', 0).len == 3)
|
||||
@ -109,7 +107,6 @@ fn test_split_nth() {
|
||||
assert (a.split_nth(',', 2).len == 2)
|
||||
assert (a.split_nth(',', 10).len == 3)
|
||||
b := "1::2::3"
|
||||
println(b)
|
||||
assert (b.split('::').len == 3)
|
||||
assert (b.split_nth('::', -1).len == 3)
|
||||
assert (b.split_nth('::', 0).len == 3)
|
||||
@ -117,19 +114,16 @@ fn test_split_nth() {
|
||||
assert (b.split_nth('::', 2).len == 2)
|
||||
assert (b.split_nth('::', 10).len == 3)
|
||||
c := "ABCDEF"
|
||||
println(c)
|
||||
println(c.split('').len)
|
||||
assert (c.split('').len == 6)
|
||||
assert (c.split_nth('', 3).len == 3)
|
||||
assert (c.split_nth('BC', -1).len == 2)
|
||||
d := ","
|
||||
println(d)
|
||||
assert (d.split(',').len == 2)
|
||||
assert (d.split_nth('', 3).len == 1)
|
||||
assert (d.split_nth(',', -1).len == 2)
|
||||
assert (d.split_nth(',', 3).len == 2)
|
||||
e := ",,,0,,,,,a,,b,"
|
||||
println(e)
|
||||
// assert (e.split(',,').len == 5)
|
||||
// assert (e.split_nth(',,', 3).len == 2)
|
||||
assert (e.split_nth(',', -1).len == 12)
|
||||
|
@ -1,5 +1,6 @@
|
||||
fn test_utf8_char_len() {
|
||||
assert utf8_char_len(`a`) == 1
|
||||
println(utf8_char_len(`a`))
|
||||
s := 'п'
|
||||
assert utf8_char_len(s[0]) == 2
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ struct CC {
|
||||
mut:
|
||||
b BB
|
||||
nums []int
|
||||
aarr []A
|
||||
aarr []AA
|
||||
num int
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ fn test_struct_levels() {
|
||||
assert c.b.a.nums[1] == 2
|
||||
c.b.a.nums [0] = 7
|
||||
assert c.b.a.nums[0] == 7
|
||||
c.aarr << A{val:8}
|
||||
c.aarr << AA{val:8}
|
||||
assert c.aarr.len == 1
|
||||
assert c.aarr[0].val == 8
|
||||
c.num = 20
|
||||
|
@ -270,14 +270,14 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
||||
match node {
|
||||
ast.AssertStmt {
|
||||
g.writeln('// assert')
|
||||
g.write('if (!(')
|
||||
g.write('if ((')
|
||||
g.expr(it.expr)
|
||||
g.writeln(')) {')
|
||||
g.writeln('g_test_fails++;')
|
||||
g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");')
|
||||
g.writeln('} else {')
|
||||
g.writeln('g_test_oks++;')
|
||||
// g.writeln('puts("OK $g.fn_decl.name");')
|
||||
g.writeln('} else {')
|
||||
g.writeln('g_test_fails++;')
|
||||
g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");')
|
||||
g.writeln('}')
|
||||
}
|
||||
ast.AssignStmt {
|
||||
@ -952,7 +952,13 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.infix_expr(it)
|
||||
}
|
||||
ast.IntegerLiteral {
|
||||
g.write(it.val.int().str())
|
||||
if it.val.starts_with('0o') {
|
||||
g.write('0')
|
||||
g.write(it.val[2..])
|
||||
}
|
||||
else {
|
||||
g.write(it.val) // .int().str())
|
||||
}
|
||||
}
|
||||
ast.MatchExpr {
|
||||
g.match_expr(it)
|
||||
|
Loading…
Reference in New Issue
Block a user