Added some extra tests for parse_range
parent
f92a20fcf8
commit
799fe2e454
|
@ -17,17 +17,15 @@ fn parse_range(s string, min u32, max u32) ?[]u32 {
|
|||
if s != '*' {
|
||||
exps := s.split('/')
|
||||
|
||||
start = math.min(max, math.max(exps[0].u32(), min))
|
||||
|
||||
if exps.len > 1 {
|
||||
interval = exps[1].u32()
|
||||
}
|
||||
// Here, s solely consists of a number, so that's the only value we
|
||||
// should return.
|
||||
else {
|
||||
return [exps[0].u32()]
|
||||
}
|
||||
|
||||
if exps[0] != '*' {
|
||||
start = math.max(exps[0].u32(), min)
|
||||
return [start]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,3 +7,31 @@ fn test_parse_star_range() ? {
|
|||
fn test_parse_number() ? {
|
||||
assert parse_range('4', 0, 5) ? == [u32(4)]
|
||||
}
|
||||
|
||||
fn test_parse_number_too_large() ? {
|
||||
assert parse_range('10', 0, 6) ? == [u32(6)]
|
||||
}
|
||||
|
||||
fn test_parse_number_too_small() ? {
|
||||
assert parse_range('0', 2, 6) ? == [u32(2)]
|
||||
}
|
||||
|
||||
fn test_parse_step_star() ? {
|
||||
assert parse_range('*/4', 0, 20) ? == [u32(0), 4, 8, 12, 16, 20]
|
||||
}
|
||||
|
||||
fn test_parse_step_star_too_large() ? {
|
||||
assert parse_range('*/21', 0, 20) ? == [u32(0)]
|
||||
}
|
||||
|
||||
fn test_parse_step_number() ? {
|
||||
assert parse_range('5/4', 0, 20) ? == [u32(5), 9, 13, 17]
|
||||
}
|
||||
|
||||
fn test_parse_step_number_too_large() ? {
|
||||
assert parse_range('10/4', 0, 5) ? == [u32(5)]
|
||||
}
|
||||
|
||||
fn test_parse_step_number_too_small() ? {
|
||||
assert parse_range('2/4', 5, 10) ? == [u32(5), 9]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue