Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 1 | from xproto_test_base import * |
| 2 | |
| 3 | class XProtoTargetTests(XProtoTest): |
| 4 | def test_file_methods(self): |
| 5 | target = \ |
| 6 | """ |
| 7 | {%% if file_exists("%s") %%} |
| 8 | {{ include_file("%s") }} |
| 9 | {%% endif %%} |
| 10 | """%(TEST_FILE, TEST_FILE) |
| 11 | |
| 12 | self.generate(target=target) |
| 13 | self.assertIn(TEST_OUTPUT, self.get_output()) |
| 14 | |
| 15 | def test_xproto_lib(self): |
| 16 | target = \ |
| 17 | """ |
| 18 | {{ xproto_first_non_empty([None, None, None, None, None, None, "Eureka"]) }} |
| 19 | """ |
| 20 | self.generate(target=target) |
| 21 | self.assertIn("Eureka", self.get_output()) |
| 22 | |
| 23 | def test_context(self): |
| 24 | target = \ |
| 25 | """ |
| 26 | {{ context.what }} |
| 27 | """ |
| 28 | self.generate(target=target, kv='what:what is what') |
| 29 | self.assertIn("what is what", self.get_output()) |
| 30 | |
Sapan Bhatia | 7886e12 | 2017-05-17 11:19:39 +0200 | [diff] [blame^] | 31 | def test_pluralize(self): |
| 32 | proto = \ |
| 33 | """ |
| 34 | message TestPluralize { |
| 35 | // The following field has an explicitly specified plural |
| 36 | required int anecdote = 1 [plural = "data"]; |
| 37 | // The following fields have automatically computed plurals |
| 38 | required int sheep = 2; |
| 39 | required int radius = 2; |
| 40 | required int slice = 2; |
| 41 | required int network = 2; |
| 42 | required int omf_friendly = 2; |
| 43 | } |
| 44 | """ |
| 45 | |
| 46 | target = \ |
| 47 | """ |
| 48 | {% for m in proto.messages.0.fields -%} |
| 49 | {{ xproto_pluralize(m) }}, |
| 50 | {%- endfor %} |
| 51 | """ |
| 52 | self.generate(xproto=proto, target=target) |
| 53 | self.assertEqual("data,sheep,radii,slices,networks,omf_friendlies", self.get_output().lstrip().rstrip().rstrip(',')) |
| 54 | |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 55 | if __name__ == '__main__': |
| 56 | unittest.main() |
| 57 | |
| 58 | |