Skip to content

Commit af29810

Browse files
committed
fix testcases
1 parent 04a7f80 commit af29810

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

src/combinator/mod.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,105 +56,111 @@ pub fn record<I>(input: State<I>) -> ParseResult<LCOVRecord, State<I>> where I:
5656
#[cfg(test)]
5757
mod tests {
5858
use super::*;
59-
use combine:: { parser, Parser };
59+
use combine:: { parser, Parser, State };
6060
use record:: { LCOVRecord, LineData, FunctionName, FunctionData, BranchData };
6161

62+
fn parse_record(input: &str) -> LCOVRecord {
63+
let input = State::new(input);
64+
let (result, _) = parser(record).parse(input).unwrap();
65+
result
66+
}
67+
6268
#[test]
6369
fn test_name() {
64-
let result = parser(record).parse("TN:test_name\n");
65-
assert_eq!(result.unwrap(), (LCOVRecord::TestName(Some("test_name".to_string())), ""));
70+
let with_testname = parse_record("TN:test_name\n");
71+
assert_eq!(with_testname, LCOVRecord::TestName(Some("test_name".to_string())));
6672

67-
let result = parser(record).parse("TN:\n");
68-
assert_eq!(result.unwrap(), (LCOVRecord::TestName(None), ""));
73+
let without_testname = parse_record("TN:\n");
74+
assert_eq!(without_testname, LCOVRecord::TestName(None));
6975
}
7076

7177
#[test]
7278
fn source_file() {
73-
let result = parser(record).parse("SF:/path/to/source.rs\n");
74-
assert_eq!(result.unwrap(), (LCOVRecord::SourceFile("/path/to/source.rs".to_string()), ""));
79+
let result = parse_record("SF:/path/to/source.rs\n");
80+
assert_eq!(result, LCOVRecord::SourceFile("/path/to/source.rs".to_string()));
7581
}
7682

7783
#[test]
7884
fn data() {
79-
let result = parser(record).parse("DA:1,2\n");
85+
let result = parse_record("DA:1,2\n");
8086
let line = LineData { line: 1, count: 2, checksum: None };
81-
assert_eq!(result.unwrap(), (LCOVRecord::Data(line), ""));
87+
assert_eq!(result, LCOVRecord::Data(line));
8288
}
8389

8490
#[test]
8591
fn data_with_checksum() {
86-
let result = parser(record).parse("DA:1,2,3sdfjiji56\n");
92+
let result = parse_record("DA:1,2,3sdfjiji56\n");
8793
let line = LineData { line: 1, count: 2, checksum: Some("3sdfjiji56".to_string()) };
88-
assert_eq!(result.unwrap(), (LCOVRecord::Data(line), ""));
94+
assert_eq!(result, LCOVRecord::Data(line));
8995
}
9096

9197
#[test]
9298
fn function_name() {
93-
let result = parser(record).parse("FN:5,main\n");
99+
let result = parse_record("FN:5,main\n");
94100
let func = FunctionName { name: "main".to_string(), line: 5 };
95-
assert_eq!(result.unwrap(), (LCOVRecord::FunctionName(func), ""));
101+
assert_eq!(result, LCOVRecord::FunctionName(func));
96102
}
97103

98104
#[test]
99105
fn function_data() {
100-
let result = parser(record).parse("FNDA:5,main\n");
106+
let result = parse_record("FNDA:5,main\n");
101107
let func_data = FunctionData { name: "main".to_string(), count: 5 };
102-
assert_eq!(result.unwrap(), (LCOVRecord::FunctionData(func_data), ""));
108+
assert_eq!(result, LCOVRecord::FunctionData(func_data));
103109
}
104110

105111
#[test]
106112
fn functions_found() {
107-
let result = parser(record).parse("FNF:10\n");
108-
assert_eq!(result.unwrap(), (LCOVRecord::FunctionsFound(10), ""));
113+
let result = parse_record("FNF:10\n");
114+
assert_eq!(result, LCOVRecord::FunctionsFound(10));
109115
}
110116

111117
#[test]
112118
fn functions_hit() {
113-
let result = parser(record).parse("FNH:10\n");
114-
assert_eq!(result.unwrap(), (LCOVRecord::FunctionsHit(10), ""));
119+
let result = parse_record("FNH:10\n");
120+
assert_eq!(result, LCOVRecord::FunctionsHit(10));
115121
}
116122

117123
#[test]
118124
fn lines_hit() {
119-
let result = parser(record).parse("LH:5\n");
120-
assert_eq!(result.unwrap(), (LCOVRecord::LinesHit(5), ""));
125+
let result = parse_record("LH:5\n");
126+
assert_eq!(result, LCOVRecord::LinesHit(5));
121127
}
122128

123129
#[test]
124130
fn lines_found() {
125-
let result = parser(record).parse("LF:10\n");
126-
assert_eq!(result.unwrap(), (LCOVRecord::LinesFound(10), ""));
131+
let result = parse_record("LF:10\n");
132+
assert_eq!(result, LCOVRecord::LinesFound(10));
127133
}
128134

129135
#[test]
130136
fn branch_data() {
137+
let result = parse_record("BRDA:1,2,3,-\n");
131138
let branch = BranchData { line: 1, block: 2, branch: 3, taken: 0 };
132-
let result = parser(record).parse("BRDA:1,2,3,-\n");
133-
assert_eq!(result.unwrap(), (LCOVRecord::BranchData(branch), ""));
139+
assert_eq!(result, LCOVRecord::BranchData(branch));
134140
}
135141

136142
#[test]
137143
fn branch_data_with_branch_times() {
144+
let result = parse_record("BRDA:1,2,3,4\n");
138145
let branch = BranchData { line: 1, block: 2, branch: 3, taken: 4 };
139-
let result = parser(record).parse("BRDA:1,2,3,4\n");
140-
assert_eq!(result.unwrap(), (LCOVRecord::BranchData(branch), ""));
146+
assert_eq!(result, LCOVRecord::BranchData(branch));
141147
}
142148

143149
#[test]
144150
fn branches_found() {
145-
let result = parser(record).parse("BRF:10\n");
146-
assert_eq!(result.unwrap(), (LCOVRecord::BranchesFound(10), ""));
151+
let result = parse_record("BRF:10\n");
152+
assert_eq!(result, LCOVRecord::BranchesFound(10));
147153
}
148154

149155
#[test]
150156
fn branches_hit() {
151-
let result = parser(record).parse("BRH:10\n");
152-
assert_eq!(result.unwrap(), (LCOVRecord::BranchesHit(10), ""));
157+
let result = parse_record("BRH:10\n");
158+
assert_eq!(result, LCOVRecord::BranchesHit(10));
153159
}
154160

155161
#[test]
156162
fn end_of_record() {
157-
let result = parser(record).parse("end_of_record\n");
158-
assert_eq!(result.unwrap(), (LCOVRecord::EndOfRecord, ""));
163+
let result = parse_record("end_of_record\n");
164+
assert_eq!(result, LCOVRecord::EndOfRecord);
159165
}
160166
}

0 commit comments

Comments
 (0)