diff --git a/integration/tests/variables.curl b/integration/tests/variables.curl index b9db3c482..4e151ffdf 100644 --- a/integration/tests/variables.curl +++ b/integration/tests/variables.curl @@ -1 +1 @@ -curl 'http://localhost:8000/variables' -H 'Content-Type: application/json' --data $'{\n "name": "Jennifer",\n "age": 30,\n "height": 1.700000000000000000,\n "female": true,\n "id": "123",\n "a_null": null\n}' +curl 'http://localhost:8000/variables' -H 'Name: Jennifer' -H 'Age: 30' -H 'Height: 1.700000000000000000' -H 'Female: true' -H 'Id: 123' -H 'A_Null: null' -H 'Content-Type: application/json' --data $'{\n "name": "Jennifer",\n "age": 30,\n "height": 1.700000000000000000,\n "female": true,\n "id": "123",\n "a_null": null\n}' diff --git a/integration/tests/variables.html b/integration/tests/variables.html index a44bbdb51..0203398a8 100644 --- a/integration/tests/variables.html +++ b/integration/tests/variables.html @@ -1 +1 @@ -
POST http://localhost:8000/variables
{ "name": "{{name}}", "age": {{age}}, "height": {{height}}, "female": {{female}}, "id": "{{id}}", "a_null": {{a_null}}}
HTTP/* 200[Asserts]variable "name" equals "Jennifer"variable "female" equals truevariable "age" equals 30variable "height" equals 1.70variable "a_null" equals nullvariable "id" equals "123"
\ No newline at end of file +
POST http://localhost:8000/variables
Name: {{name}}Age: {{age}}Height: {{height}}Female: {{female}}Id: {{my-id}}A_Null: {{a_null}}{ "name": "{{name}}", "age": {{age}}, "height": {{height}}, "female": {{female}}, "id": "{{my-id}}", "a_null": {{a_null}}}
HTTP/* 200[Asserts]variable "name" equals "Jennifer"variable "female" equals truevariable "age" equals 30variable "height" equals 1.70variable "a_null" equals nullvariable "my-id" equals "123"
\ No newline at end of file diff --git a/integration/tests/variables.hurl b/integration/tests/variables.hurl index ac9dd9585..36606c946 100644 --- a/integration/tests/variables.hurl +++ b/integration/tests/variables.hurl @@ -1,10 +1,16 @@ POST http://localhost:8000/variables +Name: {{name}} +Age: {{age}} +Height: {{height}} +Female: {{female}} +Id: {{my-id}} +A_Null: {{a_null}} { "name": "{{name}}", "age": {{age}}, "height": {{height}}, "female": {{female}}, - "id": "{{id}}", + "id": "{{my-id}}", "a_null": {{a_null}} } @@ -15,4 +21,4 @@ variable "female" equals true variable "age" equals 30 variable "height" equals 1.70 variable "a_null" equals null -variable "id" equals "123" +variable "my-id" equals "123" diff --git a/integration/tests/variables.json b/integration/tests/variables.json index ce35ac529..ab95acac6 100644 --- a/integration/tests/variables.json +++ b/integration/tests/variables.json @@ -1 +1 @@ -{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/variables","body":{"type":"json","value":{"name":"{{name}}","age":"{{age}}","height":"{{height}}","female":"{{female}}","id":"{{id}}","a_null":"{{a_null}}"}}},"response":{"status":200,"asserts":[{"query":{"type":"variable","name":"name"},"predicate":{"type":"equal","value":"Jennifer"}},{"query":{"type":"variable","name":"female"},"predicate":{"type":"equal","value":true}},{"query":{"type":"variable","name":"age"},"predicate":{"type":"equal","value":30}},{"query":{"type":"variable","name":"height"},"predicate":{"type":"equal","value":1.70}},{"query":{"type":"variable","name":"a_null"},"predicate":{"type":"equal","value":null}},{"query":{"type":"variable","name":"id"},"predicate":{"type":"equal","value":"123"}}]}}]} \ No newline at end of file +{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/variables","headers":[{"name":"Name","value":"{{name}}"},{"name":"Age","value":"{{age}}"},{"name":"Height","value":"{{height}}"},{"name":"Female","value":"{{female}}"},{"name":"Id","value":"{{my-id}}"},{"name":"A_Null","value":"{{a_null}}"}],"body":{"type":"json","value":{"name":"{{name}}","age":"{{age}}","height":"{{height}}","female":"{{female}}","id":"{{my-id}}","a_null":"{{a_null}}"}}},"response":{"status":200,"asserts":[{"query":{"type":"variable","name":"name"},"predicate":{"type":"equal","value":"Jennifer"}},{"query":{"type":"variable","name":"female"},"predicate":{"type":"equal","value":true}},{"query":{"type":"variable","name":"age"},"predicate":{"type":"equal","value":30}},{"query":{"type":"variable","name":"height"},"predicate":{"type":"equal","value":1.70}},{"query":{"type":"variable","name":"a_null"},"predicate":{"type":"equal","value":null}},{"query":{"type":"variable","name":"my-id"},"predicate":{"type":"equal","value":"123"}}]}}]} \ No newline at end of file diff --git a/integration/tests/variables.properties b/integration/tests/variables.properties index 0cdfc6885..9a8c6ef8f 100644 --- a/integration/tests/variables.properties +++ b/integration/tests/variables.properties @@ -2,6 +2,6 @@ name=Jennifer age=30 height=1.70 -id="123" +my-id="123" a_null=null diff --git a/integration/tests/variables.py b/integration/tests/variables.py index 366da750b..d796a07d9 100644 --- a/integration/tests/variables.py +++ b/integration/tests/variables.py @@ -6,6 +6,13 @@ import json @app.route('/variables', methods=['POST']) def variables(): assert request.headers['Content-Type'] == 'application/json' + assert request.headers['Name'] == 'Jennifer' + assert request.headers['Age'] == '30' + assert request.headers['Female'] == 'true' + assert request.headers['Id'] == '123' + assert request.headers['Height'] == '1.700000000000000000' + assert request.headers['A_null'] == 'null' + s = request.data.decode("utf-8") data = json.loads(s) assert data['name'] == 'Jennifer' diff --git a/packages/hurl_core/src/parser/expr.rs b/packages/hurl_core/src/parser/expr.rs index a30c440c5..b23d46cf8 100644 --- a/packages/hurl_core/src/parser/expr.rs +++ b/packages/hurl_core/src/parser/expr.rs @@ -58,7 +58,7 @@ pub fn parse2(reader: &mut Reader) -> ParseResult<'static, Expr> { fn variable_name(reader: &mut Reader) -> ParseResult<'static, Variable> { let start = reader.state.clone(); - let name = reader.read_while(|c| c.is_alphanumeric() || *c == '_'); + let name = reader.read_while(|c| c.is_alphanumeric() || *c == '_' || *c == '-'); if name.is_empty() { return Err(Error { pos: start.pos, @@ -143,5 +143,14 @@ mod tests { source_info: SourceInfo::init(1, 1, 1, 5), } ); + + let mut reader = Reader::init("my-id"); + assert_eq!( + variable_name(&mut reader).unwrap(), + Variable { + name: String::from("my-id"), + source_info: SourceInfo::init(1, 1, 1, 6), + } + ); } }