Caffe2 - C++ API
A deep learning, cross platform ML framework
test_code_template.h
1 #pragma once
2 
3 #include "test/cpp/jit/test_base.h"
4 #include "test/cpp/jit/test_utils.h"
5 
6 #include "torch/csrc/jit/code_template.h"
7 
8 namespace torch {
9 namespace jit {
10 namespace test {
11 
12 static const auto ct = CodeTemplate(R"(
13  int foo($args) {
14 
15  $bar
16  $bar
17  $a+$b
18  }
19  int commatest(int a${,stuff})
20  int notest(int a${,empty,})
21  )");
22 static const auto ct_expect = R"(
23  int foo(hi, 8) {
24 
25  what
26  on many
27  lines...
28  7
29  what
30  on many
31  lines...
32  7
33  3+4
34  }
35  int commatest(int a, things..., others)
36  int notest(int a)
37  )";
38 
39 void testCodeTemplate() {
40  {
41  TemplateEnv e;
42  e.s("hi", "foo");
43  e.v("what", {"is", "this"});
44  TemplateEnv c(e);
45  c.s("hi", "foo2");
46  ASSERT_EQ(e.s("hi"), "foo");
47  ASSERT_EQ(c.s("hi"), "foo2");
48  ASSERT_EQ(e.v("what")[0], "is");
49  }
50 
51  {
52  TemplateEnv e;
53  e.v("args", {"hi", "8"});
54  e.v("bar", {"what\non many\nlines...", "7"});
55  e.s("a", "3");
56  e.s("b", "4");
57  e.v("stuff", {"things...", "others"});
58  e.v("empty", {});
59  auto s = ct.format(e);
60  // std::cout << "'" << s << "'\n";
61  // std::cout << "'" << ct_expect << "'\n";
62  ASSERT_EQ(s, ct_expect);
63  }
64 }
65 } // namespace test
66 } // namespace jit
67 } // namespace torch
Definition: module.cpp:17
Definition: jit_type.h:17