mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: remove space in front of ? and ! (#14366)
This commit is contained in:
@ -12,16 +12,16 @@ fn test_len() ? {
|
||||
assert list.len() == 0
|
||||
list.push_back(1)
|
||||
assert list.len() == 1
|
||||
list.pop_back() ?
|
||||
list.pop_back()?
|
||||
assert list.len() == 0
|
||||
}
|
||||
|
||||
fn test_first() ? {
|
||||
mut list := DoublyLinkedList<int>{}
|
||||
list.push_back(1)
|
||||
assert list.first() ? == 1
|
||||
assert list.first()? == 1
|
||||
list.push_back(2)
|
||||
assert list.first() ? == 1
|
||||
assert list.first()? == 1
|
||||
list = DoublyLinkedList<int>{}
|
||||
list.first() or { return }
|
||||
assert false
|
||||
@ -30,9 +30,9 @@ fn test_first() ? {
|
||||
fn test_last() ? {
|
||||
mut list := DoublyLinkedList<int>{}
|
||||
list.push_back(1)
|
||||
assert list.last() ? == 1
|
||||
assert list.last()? == 1
|
||||
list.push_back(2)
|
||||
assert list.last() ? == 2
|
||||
assert list.last()? == 2
|
||||
list = DoublyLinkedList<int>{}
|
||||
list.last() or { return }
|
||||
assert false
|
||||
@ -41,11 +41,11 @@ fn test_last() ? {
|
||||
fn test_push() ? {
|
||||
mut list := DoublyLinkedList<int>{}
|
||||
list.push_back(1)
|
||||
assert list.last() ? == 1
|
||||
assert list.last()? == 1
|
||||
list.push_back(2)
|
||||
assert list.last() ? == 2
|
||||
assert list.last()? == 2
|
||||
list.push_back(3)
|
||||
assert list.last() ? == 3
|
||||
assert list.last()? == 3
|
||||
}
|
||||
|
||||
fn test_pop() ? {
|
||||
@ -53,10 +53,10 @@ fn test_pop() ? {
|
||||
list.push_back(1)
|
||||
list.push_back(2)
|
||||
list.push_back(3)
|
||||
assert list.pop_back() ? == 3
|
||||
assert list.pop_back()? == 3
|
||||
list.push_back(4)
|
||||
assert list.pop_back() ? == 4
|
||||
assert list.pop_back() ? == 2
|
||||
assert list.pop_back()? == 4
|
||||
assert list.pop_back()? == 2
|
||||
list = DoublyLinkedList<int>{}
|
||||
list.pop_back() or { return }
|
||||
assert false
|
||||
@ -67,10 +67,10 @@ fn test_pop_front() ? {
|
||||
list.push_back(1)
|
||||
list.push_back(2)
|
||||
list.push_back(3)
|
||||
assert list.pop_front() ? == 1
|
||||
assert list.pop_front()? == 1
|
||||
list.push_back(4)
|
||||
assert list.pop_front() ? == 2
|
||||
assert list.pop_front() ? == 3
|
||||
assert list.pop_front()? == 2
|
||||
assert list.pop_front()? == 3
|
||||
list = DoublyLinkedList<int>{}
|
||||
list.pop_front() or { return }
|
||||
assert false
|
||||
@ -82,14 +82,14 @@ fn test_insert() ? {
|
||||
list.push_back(2)
|
||||
list.push_back(3)
|
||||
// [1, 2, 3]
|
||||
list.insert(1, 111) ?
|
||||
list.insert(1, 111)?
|
||||
// [1, 111, 2, 3]
|
||||
list.insert(3, 222) ?
|
||||
list.insert(3, 222)?
|
||||
// [1, 111, 2, 222, 3]
|
||||
assert list.pop_back() ? == 3
|
||||
assert list.pop_back() ? == 222
|
||||
assert list.pop_front() ? == 1
|
||||
assert list.pop_front() ? == 111
|
||||
assert list.pop_back()? == 3
|
||||
assert list.pop_back()? == 222
|
||||
assert list.pop_front()? == 1
|
||||
assert list.pop_front()? == 111
|
||||
}
|
||||
|
||||
fn test_push_front() ? {
|
||||
@ -98,7 +98,7 @@ fn test_push_front() ? {
|
||||
list.push_back(2)
|
||||
list.push_back(3)
|
||||
list.push_front(111)
|
||||
assert list.first() ? == 111
|
||||
assert list.first()? == 111
|
||||
}
|
||||
|
||||
fn test_delete() ? {
|
||||
@ -107,12 +107,12 @@ fn test_delete() ? {
|
||||
list.push_back(1)
|
||||
list.push_back(2)
|
||||
list.delete(1)
|
||||
assert list.first() ? == 0
|
||||
assert list.last() ? == 2
|
||||
assert list.first()? == 0
|
||||
assert list.last()? == 2
|
||||
assert list.len() == 2
|
||||
list.delete(1)
|
||||
assert list.first() ? == 0
|
||||
assert list.last() ? == 0
|
||||
assert list.first()? == 0
|
||||
assert list.last()? == 0
|
||||
assert list.len() == 1
|
||||
list.delete(0)
|
||||
assert list.len() == 0
|
||||
@ -147,7 +147,7 @@ fn test_index() ? {
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
assert list.index(i * 10) ? == i
|
||||
assert list.index(i * 10)? == i
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ fn default_setup() (MyReceiver, fsm.StateMachine) {
|
||||
fn test_statemachine_number_of_callbacks_correct_when_single_transition() ? {
|
||||
mut receiver, mut s := default_setup()
|
||||
|
||||
s.run(receiver) ?
|
||||
s.run(receiver)?
|
||||
|
||||
assert receiver.data.len == 3
|
||||
}
|
||||
@ -25,7 +25,7 @@ fn test_statemachine_number_of_callbacks_correct_when_single_transition() ? {
|
||||
fn test_statemachine_sequence_works_when_typical() ? {
|
||||
mut receiver, mut s := default_setup()
|
||||
|
||||
s.run(receiver) ?
|
||||
s.run(receiver)?
|
||||
|
||||
assert receiver.data[0] == 'on_state_exit: A -> B'
|
||||
assert receiver.data[1] == 'on_state_entry: A -> B'
|
||||
@ -36,7 +36,7 @@ fn test_statemachine_works_when_final_state() ? {
|
||||
mut receiver, mut s := default_setup()
|
||||
|
||||
// current state `A`, with a possible transition to `B`:
|
||||
s.run(receiver) ? // run should not error here
|
||||
s.run(receiver)? // run should not error here
|
||||
|
||||
// Note: run will now return error, because for state `B`,
|
||||
// there are no more transitions:
|
||||
|
@ -13,7 +13,7 @@ pub fn read_file(file string) ?[]string {
|
||||
|
||||
pub fn extract_transitions(line string) ?string {
|
||||
mut result := ' '
|
||||
first_comma := line.index(',') ?
|
||||
first_comma := line.index(',')?
|
||||
second_comma := line.index_after(',', first_comma + 1)
|
||||
|
||||
from := line[..first_comma]
|
||||
@ -32,11 +32,11 @@ pub fn get_transitions(line string) ?string {
|
||||
pub fn main() {
|
||||
mut fp := flag.new_flag_parser(os.args)
|
||||
file := fp.string('file', `f`, '', 'input V file with transitions to generate graph from.')
|
||||
lines := read_file(file) ?
|
||||
lines := read_file(file)?
|
||||
println('digraph fsm {')
|
||||
for line in lines {
|
||||
if line.contains('add_transition') {
|
||||
println(get_transitions(line) ?)
|
||||
println(get_transitions(line)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,11 @@ fn test_min_heap() ? {
|
||||
heap.insert(4)
|
||||
heap.insert(1)
|
||||
|
||||
assert heap.pop() ? == 0
|
||||
assert heap.pop() ? == 1
|
||||
assert heap.pop() ? == 2
|
||||
assert heap.pop() ? == 4
|
||||
assert heap.pop() ? == 8
|
||||
assert heap.pop()? == 0
|
||||
assert heap.pop()? == 1
|
||||
assert heap.pop()? == 2
|
||||
assert heap.pop()? == 4
|
||||
assert heap.pop()? == 8
|
||||
if _ := heap.pop() {
|
||||
panic('expected none')
|
||||
}
|
||||
@ -35,11 +35,11 @@ fn test_min_heap_custom() ? {
|
||||
heap.insert(Item{'foo', 100})
|
||||
heap.insert(Item{'bar', 80})
|
||||
|
||||
assert heap.pop() ?.data == 'foo'
|
||||
assert heap.pop() ?.data == 'bar'
|
||||
assert heap.pop() ?.data == 'baz'
|
||||
assert heap.pop() ?.data == 'buz'
|
||||
assert heap.pop() ?.data == 'qux'
|
||||
assert heap.pop()?.data == 'foo'
|
||||
assert heap.pop()?.data == 'bar'
|
||||
assert heap.pop()?.data == 'baz'
|
||||
assert heap.pop()?.data == 'buz'
|
||||
assert heap.pop()?.data == 'qux'
|
||||
if _ := heap.pop() {
|
||||
panic('expected none')
|
||||
}
|
||||
@ -56,12 +56,12 @@ fn test_heap_len() ? {
|
||||
heap.insert(1)
|
||||
|
||||
assert heap.len() == 5
|
||||
heap.pop() ?
|
||||
heap.pop() ?
|
||||
heap.pop() ?
|
||||
heap.pop()?
|
||||
heap.pop()?
|
||||
heap.pop()?
|
||||
assert heap.len() == 2
|
||||
heap.pop() ?
|
||||
heap.pop() ?
|
||||
heap.pop()?
|
||||
heap.pop()?
|
||||
assert heap.len() == 0
|
||||
heap.pop() or {}
|
||||
assert heap.len() == 0
|
||||
|
@ -12,16 +12,16 @@ fn test_len() ? {
|
||||
assert list.len() == 0
|
||||
list.push(1)
|
||||
assert list.len() == 1
|
||||
list.pop() ?
|
||||
list.pop()?
|
||||
assert list.len() == 0
|
||||
}
|
||||
|
||||
fn test_first() ? {
|
||||
mut list := LinkedList<int>{}
|
||||
list.push(1)
|
||||
assert list.first() ? == 1
|
||||
assert list.first()? == 1
|
||||
list.push(2)
|
||||
assert list.first() ? == 1
|
||||
assert list.first()? == 1
|
||||
list = LinkedList<int>{}
|
||||
list.first() or { return }
|
||||
assert false
|
||||
@ -30,9 +30,9 @@ fn test_first() ? {
|
||||
fn test_last() ? {
|
||||
mut list := LinkedList<int>{}
|
||||
list.push(1)
|
||||
assert list.last() ? == 1
|
||||
assert list.last()? == 1
|
||||
list.push(2)
|
||||
assert list.last() ? == 2
|
||||
assert list.last()? == 2
|
||||
list = LinkedList<int>{}
|
||||
list.last() or { return }
|
||||
assert false
|
||||
@ -41,10 +41,10 @@ fn test_last() ? {
|
||||
fn test_index() ? {
|
||||
mut list := LinkedList<int>{}
|
||||
list.push(1)
|
||||
assert list.index(0) ? == 1
|
||||
assert list.index(0)? == 1
|
||||
list.push(2)
|
||||
assert list.index(1) ? == 2
|
||||
list.pop() ?
|
||||
assert list.index(1)? == 2
|
||||
list.pop()?
|
||||
list.index(1) or { return }
|
||||
assert false
|
||||
}
|
||||
@ -52,11 +52,11 @@ fn test_index() ? {
|
||||
fn test_push() ? {
|
||||
mut list := LinkedList<int>{}
|
||||
list.push(1)
|
||||
assert list.last() ? == 1
|
||||
assert list.last()? == 1
|
||||
list.push(2)
|
||||
assert list.last() ? == 2
|
||||
assert list.last()? == 2
|
||||
list.push(3)
|
||||
assert list.last() ? == 3
|
||||
assert list.last()? == 3
|
||||
}
|
||||
|
||||
fn test_pop() ? {
|
||||
@ -64,10 +64,10 @@ fn test_pop() ? {
|
||||
list.push(1)
|
||||
list.push(2)
|
||||
list.push(3)
|
||||
assert list.pop() ? == 3
|
||||
assert list.pop()? == 3
|
||||
list.push(4)
|
||||
assert list.pop() ? == 4
|
||||
assert list.pop() ? == 2
|
||||
assert list.pop()? == 4
|
||||
assert list.pop()? == 2
|
||||
list = LinkedList<int>{}
|
||||
list.pop() or { return }
|
||||
assert false
|
||||
@ -78,10 +78,10 @@ fn test_shift() ? {
|
||||
list.push(1)
|
||||
list.push(2)
|
||||
list.push(3)
|
||||
assert list.shift() ? == 1
|
||||
assert list.shift()? == 1
|
||||
list.push(4)
|
||||
assert list.shift() ? == 2
|
||||
assert list.shift() ? == 3
|
||||
assert list.shift()? == 2
|
||||
assert list.shift()? == 3
|
||||
list = LinkedList<int>{}
|
||||
list.shift() or { return }
|
||||
assert false
|
||||
@ -102,7 +102,7 @@ fn test_prepend() ? {
|
||||
list.push(2)
|
||||
list.push(3)
|
||||
list.prepend(111)
|
||||
assert list.first() ? == 111
|
||||
assert list.first()? == 111
|
||||
}
|
||||
|
||||
fn test_str() ? {
|
||||
|
@ -12,16 +12,16 @@ fn test_len() ? {
|
||||
assert queue.len() == 0
|
||||
queue.push(1)
|
||||
assert queue.len() == 1
|
||||
queue.pop() ?
|
||||
queue.pop()?
|
||||
assert queue.len() == 0
|
||||
}
|
||||
|
||||
fn test_peek() ? {
|
||||
mut queue := Queue<int>{}
|
||||
queue.push(1)
|
||||
assert queue.peek() ? == 1
|
||||
assert queue.peek()? == 1
|
||||
queue.push(2)
|
||||
assert queue.peek() ? == 1
|
||||
assert queue.peek()? == 1
|
||||
queue = Queue<int>{}
|
||||
queue.peek() or { return }
|
||||
assert false
|
||||
@ -30,9 +30,9 @@ fn test_peek() ? {
|
||||
fn test_last() ? {
|
||||
mut queue := Queue<int>{}
|
||||
queue.push(1)
|
||||
assert queue.last() ? == 1
|
||||
assert queue.last()? == 1
|
||||
queue.push(2)
|
||||
assert queue.last() ? == 2
|
||||
assert queue.last()? == 2
|
||||
queue = Queue<int>{}
|
||||
queue.last() or { return }
|
||||
assert false
|
||||
@ -41,10 +41,10 @@ fn test_last() ? {
|
||||
fn test_index() ? {
|
||||
mut queue := Queue<int>{}
|
||||
queue.push(1)
|
||||
assert queue.index(0) ? == 1
|
||||
assert queue.index(0)? == 1
|
||||
queue.push(2)
|
||||
assert queue.index(1) ? == 2
|
||||
queue.pop() ?
|
||||
assert queue.index(1)? == 2
|
||||
queue.pop()?
|
||||
queue.index(1) or { return }
|
||||
assert false
|
||||
}
|
||||
@ -53,7 +53,7 @@ fn test_push() ? {
|
||||
mut queue := Queue<int>{}
|
||||
queue.push(1)
|
||||
queue.push(2)
|
||||
assert queue.peek() ? == 1
|
||||
assert queue.peek()? == 1
|
||||
}
|
||||
|
||||
fn test_pop() ? {
|
||||
@ -61,10 +61,10 @@ fn test_pop() ? {
|
||||
queue.push(1)
|
||||
queue.push(2)
|
||||
queue.push(3)
|
||||
assert queue.pop() ? == 1
|
||||
assert queue.pop()? == 1
|
||||
queue.push(4)
|
||||
assert queue.pop() ? == 2
|
||||
assert queue.pop() ? == 3
|
||||
assert queue.pop()? == 2
|
||||
assert queue.pop()? == 3
|
||||
queue = Queue<int>{}
|
||||
queue.pop() or { return }
|
||||
assert false
|
||||
|
@ -12,16 +12,16 @@ fn test_len() ? {
|
||||
assert stack.len() == 0
|
||||
stack.push(1)
|
||||
assert stack.len() == 1
|
||||
stack.pop() ?
|
||||
stack.pop()?
|
||||
assert stack.len() == 0
|
||||
}
|
||||
|
||||
fn test_peek() ? {
|
||||
mut stack := dt.Stack<int>{}
|
||||
stack.push(1)
|
||||
assert stack.peek() ? == 1
|
||||
assert stack.peek()? == 1
|
||||
stack.push(2)
|
||||
assert stack.peek() ? == 2
|
||||
assert stack.peek()? == 2
|
||||
stack = dt.Stack<int>{}
|
||||
stack.peek() or { return }
|
||||
assert false
|
||||
@ -30,11 +30,11 @@ fn test_peek() ? {
|
||||
fn test_push() ? {
|
||||
mut stack := dt.Stack<int>{}
|
||||
stack.push(1)
|
||||
assert stack.peek() ? == 1
|
||||
assert stack.peek()? == 1
|
||||
stack.push(2)
|
||||
assert stack.peek() ? == 2
|
||||
assert stack.peek()? == 2
|
||||
stack.push(3)
|
||||
assert stack.peek() ? == 3
|
||||
assert stack.peek()? == 3
|
||||
}
|
||||
|
||||
fn test_pop() ? {
|
||||
@ -42,10 +42,10 @@ fn test_pop() ? {
|
||||
stack.push(1)
|
||||
stack.push(2)
|
||||
stack.push(3)
|
||||
assert stack.pop() ? == 3
|
||||
assert stack.pop()? == 3
|
||||
stack.push(4)
|
||||
assert stack.pop() ? == 4
|
||||
assert stack.pop() ? == 2
|
||||
assert stack.pop()? == 4
|
||||
assert stack.pop()? == 2
|
||||
stack = dt.Stack<int>{}
|
||||
stack.pop() or { return }
|
||||
assert false
|
||||
|
Reference in New Issue
Block a user