Added tests for 'variables' function
diff --git a/test/Makefile b/test/Makefile
index 91570fa..85d5ee9 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,7 +1,7 @@
LEVEL = 4
-test: spec-examples spec-examples-by-section extended
+test: spec-examples spec-examples-by-section extended variables
spec-examples:
PYTHONPATH=..:$(PYTHONPATH) python uritemplate_test.py cases/spec-examples.json $(LEVEL)
@@ -15,3 +15,5 @@
negative:
PYTHONPATH=..:$(PYTHONPATH) python uritemplate_test.py cases/negative-tests.json $(LEVEL)
+variables:
+ PYTHONPATH=..:$(PYTHONPATH) python variables_test.py
diff --git a/test/variables_test.py b/test/variables_test.py
new file mode 100644
index 0000000..7a45d34
--- /dev/null
+++ b/test/variables_test.py
@@ -0,0 +1,83 @@
+'''Tests for the variables function'''
+
+import unittest
+
+import uritemplate
+
+
+class VariablesTests(unittest.TestCase):
+
+ def test_simple(self):
+ template = 'http://example.com/{x,y}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y']))
+
+ def test_simple2(self):
+ template = 'http://example.com/{x,y}/{z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_reserved(self):
+ template = 'http://example.com/{+x,y}/{+z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_fragment(self):
+ template = 'http://example.com/{#x,y},{#z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_label(self):
+ template = 'http://{.x,y,z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_path_segment(self):
+ template = 'http://example.com{/x,y}/w{/z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_parameter(self):
+ template = 'http://example.com{;x,y}{;z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_query(self):
+ template = 'http://example.com{?x,y,z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_query_continuation(self):
+ template = 'http://example.com?a=1&b=2{&x,y}&r=13{&z}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_prefix_modifier(self):
+ template = 'http://example.com{/x:5,y:7}{/z:2}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_explode_modifier(self):
+ template = 'http://example.com{/x*,y*}/page{/z*}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['x', 'y', 'z']))
+
+ def test_mixed_expansion_types(self):
+ template = 'http://{a,b}.com{;c,d}{/e,f}/page{?g,h}{&i,j}{#k,l}'
+ vars = uritemplate.variables(template)
+ expected_vars = set('abcdefghijkl')
+ self.assertEquals(vars, expected_vars)
+
+ def test_overlapping_expansion(self):
+ template = 'http://{a,b}.com{;a,b}{/a,b}/page{?a,b}{&a,b}{#a,b}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['a', 'b']))
+
+ def test_partially_overlapping(self):
+ template = 'http://{.a,b}{/b,c}/{c,d}'
+ vars = uritemplate.variables(template)
+ self.assertEquals(vars, set(['a', 'b', 'c', 'd']))
+
+
+if __name__ == '__main__':
+ unittest.main()