Merge pull request #259 from Orange-OpenSource/fix/accept-hyphen-in-variable-name

Accept hyphen in variable name
This commit is contained in:
Fabrice Reix 2021-09-10 17:54:49 +02:00 committed by GitHub
commit 5584feab5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 7 deletions

View File

@ -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}'

View File

@ -1 +1 @@
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/variables</span></span></div><span class="line">{<span class="line"> "name": "{{name}}",</span><span class="line"> "age": {{age}},</span><span class="line"> "height": {{height}},</span><span class="line"> "female": {{female}},</span><span class="line"> "id": "{{id}}",</span><span class="line"> "a_null": {{a_null}}</span><span class="line">}</span></span><div class="response"><span class="line"></span><span class="line"><span class="version">HTTP/*</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span><span class="line"><span class="query-type">variable</span> <span class="string">"name"</span> <span class="predicate-type">equals</span> <span class="string">"Jennifer"</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"female"</span> <span class="predicate-type">equals</span> <span class="boolean">true</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"age"</span> <span class="predicate-type">equals</span> <span class="number">30</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"height"</span> <span class="predicate-type">equals</span> <span class="number">1.70</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"a_null"</span> <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"id"</span> <span class="predicate-type">equals</span> <span class="string">"123"</span></span></div></div></div>
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/variables</span></span></div><span class="line"><span class="string">Name</span><span>:</span> <span class="string">{{name}}</span></span><span class="line"><span class="string">Age</span><span>:</span> <span class="string">{{age}}</span></span><span class="line"><span class="string">Height</span><span>:</span> <span class="string">{{height}}</span></span><span class="line"><span class="string">Female</span><span>:</span> <span class="string">{{female}}</span></span><span class="line"><span class="string">Id</span><span>:</span> <span class="string">{{my-id}}</span></span><span class="line"><span class="string">A_Null</span><span>:</span> <span class="string">{{a_null}}</span></span><span class="line">{<span class="line"> "name": "{{name}}",</span><span class="line"> "age": {{age}},</span><span class="line"> "height": {{height}},</span><span class="line"> "female": {{female}},</span><span class="line"> "id": "{{my-id}}",</span><span class="line"> "a_null": {{a_null}}</span><span class="line">}</span></span><div class="response"><span class="line"></span><span class="line"><span class="version">HTTP/*</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span><span class="line"><span class="query-type">variable</span> <span class="string">"name"</span> <span class="predicate-type">equals</span> <span class="string">"Jennifer"</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"female"</span> <span class="predicate-type">equals</span> <span class="boolean">true</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"age"</span> <span class="predicate-type">equals</span> <span class="number">30</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"height"</span> <span class="predicate-type">equals</span> <span class="number">1.70</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"a_null"</span> <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"><span class="query-type">variable</span> <span class="string">"my-id"</span> <span class="predicate-type">equals</span> <span class="string">"123"</span></span></div></div></div>

View File

@ -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"

View File

@ -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"}}]}}]}
{"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"}}]}}]}

View File

@ -2,6 +2,6 @@
name=Jennifer
age=30
height=1.70
id="123"
my-id="123"
a_null=null

View File

@ -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'

View File

@ -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),
}
);
}
}