-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathrest_tree_test.rb
70 lines (53 loc) · 2.58 KB
/
rest_tree_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'test/unit'
$:.unshift File.expand_path("..")
require 'rest_tree'
require 'ol'
class RestTreeTest < Test::Unit::TestCase
def test_handles?
assert RestTree.handles?(['GET http://foo.com', 'hey'])
assert ! RestTree.handles?(['HEY http://foo.com', 'hey'])
end
def test_extract_root_verb
list = ['POST http://foo.com', 'PUT hey']
assert_equal 'POST', RestTree.extract_root_verb(list)
assert_equal ['http://foo.com', 'PUT hey'], list
end
def test_extract_verb
line = 'POST hey'
assert_equal 'POST', RestTree.extract_verb(line)
assert_equal 'hey', line
line = 'DELETE'
assert_equal 'DELETE', RestTree.extract_verb(line)
assert line.empty? # Should be nothing left
assert_equal nil, RestTree.extract_verb('hiya')
end
def test_launch_inner
# Single line
verb, path, body = RestTree.launch_inner ["PUT http://localhost:5984/foo/"], nil
assert_equal ['PUT', 'http://localhost:5984/foo/', nil], [verb, path, body]
# More path
verb, path, body = RestTree.launch_inner ["GET http://localhost:5984/foo/", "bar/"], nil
assert_equal ['GET', 'http://localhost:5984/foo/bar/', nil], [verb, path, body]
# More path and verb
verb, path, body = RestTree.launch_inner ['GET http://localhost:5984/foo/', 'bar/', 'POST'], nil
assert_equal ['POST', 'http://localhost:5984/foo/bar/', nil], [verb, path, body]
# More path, verb, and body
verb, path, body = RestTree.launch_inner ['GET http://localhost:5984/foo/', 'bar/', 'POST ["txt"]'], nil
assert_equal ['POST', 'http://localhost:5984/foo/bar/', '["txt"]'], [verb, path, body]
end
def test_launch_inner_with_children
# TODO Just verb with children
verb, path, body = RestTree.launch_inner ['GET http://localhost:5984/foo/', 'POST'], ['a', 'b']
assert_equal ['POST', 'http://localhost:5984/foo/', "a\nb\n"], [verb, path, body]
# TODO Quoted children (should be ignored)
verb, path, body = RestTree.launch_inner ['GET http://localhost:5984/foo/', 'POST'], ['|a', '|b']
assert_equal ['POST', 'http://localhost:5984/foo/', nil], [verb, path, body]
end
def test_remove_before_root
# No root anywhere
assert_equal [], RestTree.remove_before_root(["CodeTree.menu/"])
assert_equal ["GET http://foo.com"], RestTree.remove_before_root(['GET http://foo.com'])
assert_equal ["GET http://foo.com"], RestTree.remove_before_root(['crap', 'GET http://foo.com'])
assert_equal ["GET http://localhost:5984/mem/"], RestTree.remove_before_root(["CodeTree.menu/", "CouchDb.menu/", ".rest/", "mem/", "GET http://localhost:5984/mem/"])
end
end