hello_world/
hello_world.rs1extern crate pythonic;
2
3use pythonic::{Argument, Block, Function, Statement};
4
5fn main() {
6 let mut program = Block::new();
7
8 let mut function = Function::new("hello",
9 vec![Argument::new("name",
10 Some("\"World\""),
11 Some("str"),
12 Some("The name to say Hello to"))],
13 &program);
14 let arguments = vec![Statement::unnamed_variable("Hello"),
15 Statement::variable("name")];
16 let function_call = Statement::function_call("print", arguments);
17 function.add_statement(function_call);
18 function.add_docstring("hello is a function that prints \"Hello\" with the given \
19 name argument.");
20
21 program.add_function(function);
22 let function_call = Statement::function_call(
23 "hello",
24 vec![
25 Statement::unnamed_variable("Chris")
26 ]);
27 program.add_statement(function_call);
28 let expected = r#"def hello(name="World"):
29 """
30 hello is a function that prints "Hello" with the given name argument.
31
32 :param name: str The name to say Hello to
33 """
34 print("Hello", name)
35
36hello("Chris")
37"#;
38 let actual = format!("{}",program);
39 assert_eq!(expected, actual);
40
41 println!("{}", actual);
42
43}