Skip to content

Commit 08e2d67

Browse files
committed
Update to build again and build with cargo
1 parent 5b292cb commit 08e2d67

File tree

11 files changed

+48
-32
lines changed

11 files changed

+48
-32
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
*.dummy
99
*-test
1010
Makefile
11+
target/
12+
doc/
13+
.*.swp

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "rust"
3+
version = "0.0.0"
4+
5+
authors = ["Your Name <your@email.com>"]
6+
tags = []
7+
8+
[[lib]]
9+
name = "rust"
10+
path = "src/lib.rs"
11+
12+
[dependencies.encoding]
13+
git = "https://github.com/lifthrasiir/rust-encoding.git"

ast.rs renamed to src/ast.rs

File renamed without changes.

color.rs renamed to src/color.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ fn parse_color_hash(value: &str) -> Option<Color> {
205205
macro_rules! from_hex(
206206
($c: expr) => {{
207207
let c = $c;
208-
match c as char {
209-
'0' .. '9' => c - ('0' as u8),
210-
'a' .. 'f' => c - ('a' as u8) + 10,
211-
'A' .. 'F' => c - ('A' as u8) + 10,
208+
match c {
209+
'0' .. '9' => (c as u8) - ('0' as u8),
210+
'a' .. 'f' => (c as u8) - ('a' as u8) + 10,
211+
'A' .. 'F' => (c as u8) - ('A' as u8) + 10,
212212
_ => return None // Not a valid color
213213
}
214214
}};
@@ -224,14 +224,14 @@ fn parse_color_hash(value: &str) -> Option<Color> {
224224

225225
match value.len() {
226226
6 => to_rgba!(
227-
from_hex!(value[0]) * 16 + from_hex!(value[1]),
228-
from_hex!(value[2]) * 16 + from_hex!(value[3]),
229-
from_hex!(value[4]) * 16 + from_hex!(value[5]),
227+
from_hex!(value.char_at(0)) * 16 + from_hex!(value.char_at(1)),
228+
from_hex!(value.char_at(2)) * 16 + from_hex!(value.char_at(3)),
229+
from_hex!(value.char_at(4)) * 16 + from_hex!(value.char_at(5)),
230230
),
231231
3 => to_rgba!(
232-
from_hex!(value[0]) * 17,
233-
from_hex!(value[1]) * 17,
234-
from_hex!(value[2]) * 17,
232+
from_hex!(value.char_at(0)) * 17,
233+
from_hex!(value.char_at(1)) * 17,
234+
from_hex!(value.char_at(2)) * 17,
235235
),
236236
_ => None
237237
}
File renamed without changes.

lib.rs renamed to src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
#![crate_id = "github.com/mozilla-servo/rust-cssparser#cssparser:0.1"]
5+
#![crate_name = "rust-cssparser"]
66
#![crate_type = "lib"]
77
#![crate_type = "dylib"]
88
#![crate_type = "rlib"]

nth.rs renamed to src/nth.rs

File renamed without changes.

parser.rs renamed to src/parser.rs

File renamed without changes.
File renamed without changes.

tests.rs renamed to src/tests.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: String) {
5858
write_whole_file(&expected_path, expected.as_slice());
5959
Command::new("colordiff")
6060
.arg("-u1000")
61-
.arg(result_path.display().to_str())
62-
.arg(expected_path.display().to_str())
63-
.status().unwrap();
64-
}).unwrap();
61+
.arg(result_path)
62+
.arg(expected_path)
63+
.status().unwrap_or_else(|e| fail!("Failed to get status of colordiff: {}", e));
64+
}).unwrap_or_else(|_e| fail!("Failed to execute task"));
6565

6666
fail!(message)
6767
}
@@ -102,84 +102,84 @@ fn run_json_tests<T: ToJson>(json_data: &str, parse: |input: &str| -> T) {
102102

103103
#[test]
104104
fn component_value_list() {
105-
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
105+
run_json_tests(include_str!("../css-parsing-tests/component_value_list.json"), |input| {
106106
tokenize(input).map(|(c, _)| c).collect::<Vec<ComponentValue>>()
107107
});
108108
}
109109

110110

111111
#[test]
112112
fn one_component_value() {
113-
run_json_tests(include_str!("css-parsing-tests/one_component_value.json"), |input| {
113+
run_json_tests(include_str!("../css-parsing-tests/one_component_value.json"), |input| {
114114
parse_one_component_value(tokenize(input))
115115
});
116116
}
117117

118118

119119
#[test]
120120
fn declaration_list() {
121-
run_json_tests(include_str!("css-parsing-tests/declaration_list.json"), |input| {
121+
run_json_tests(include_str!("../css-parsing-tests/declaration_list.json"), |input| {
122122
parse_declaration_list(tokenize(input)).collect::<Vec<Result<DeclarationListItem, SyntaxError>>>()
123123
});
124124
}
125125

126126

127127
#[test]
128128
fn one_declaration() {
129-
run_json_tests(include_str!("css-parsing-tests/one_declaration.json"), |input| {
129+
run_json_tests(include_str!("../css-parsing-tests/one_declaration.json"), |input| {
130130
parse_one_declaration(tokenize(input))
131131
});
132132
}
133133

134134

135135
#[test]
136136
fn rule_list() {
137-
run_json_tests(include_str!("css-parsing-tests/rule_list.json"), |input| {
137+
run_json_tests(include_str!("../css-parsing-tests/rule_list.json"), |input| {
138138
parse_rule_list(tokenize(input)).collect::<Vec<Result<Rule, SyntaxError>>>()
139139
});
140140
}
141141

142142

143143
#[test]
144144
fn stylesheet() {
145-
run_json_tests(include_str!("css-parsing-tests/stylesheet.json"), |input| {
145+
run_json_tests(include_str!("../css-parsing-tests/stylesheet.json"), |input| {
146146
parse_stylesheet_rules(tokenize(input)).collect::<Vec<Result<Rule, SyntaxError>>>()
147147
});
148148
}
149149

150150

151151
#[test]
152152
fn one_rule() {
153-
run_json_tests(include_str!("css-parsing-tests/one_rule.json"), |input| {
153+
run_json_tests(include_str!("../css-parsing-tests/one_rule.json"), |input| {
154154
parse_one_rule(tokenize(input))
155155
});
156156
}
157157

158158

159159
#[test]
160160
fn stylesheet_from_bytes() {
161-
run_raw_json_tests(include_str!("css-parsing-tests/stylesheet_bytes.json"),
161+
run_raw_json_tests(include_str!("../css-parsing-tests/stylesheet_bytes.json"),
162162
|input, expected| {
163163
let map = match input {
164164
json::Object(map) => map,
165165
_ => fail!("Unexpected JSON")
166166
};
167167

168168
let result = {
169-
let css = get_string(map, &"css_bytes".to_string()).unwrap().chars().map(|c| {
169+
let css = get_string(&map, &"css_bytes".to_string()).unwrap().chars().map(|c| {
170170
assert!(c as u32 <= 0xFF);
171171
c as u8
172172
}).collect::<Vec<u8>>();
173-
let protocol_encoding_label = get_string(map, &"protocol_encoding".to_string());
174-
let environment_encoding = get_string(map, &"environment_encoding".to_string())
173+
let protocol_encoding_label = get_string(&map, &"protocol_encoding".to_string());
174+
let environment_encoding = get_string(&map, &"environment_encoding".to_string())
175175
.and_then(encoding_from_whatwg_label);
176176

177177
let (mut rules, used_encoding) = parse_stylesheet_rules_from_bytes(
178178
css.as_slice(), protocol_encoding_label, environment_encoding);
179179

180180
(rules.collect::<Vec<Result<Rule, SyntaxError>>>(), used_encoding.name().to_string()).to_json()
181181
};
182-
assert_json_eq(result, expected, json::Object(map).to_str());
182+
assert_json_eq(result, expected, json::Object(map).to_pretty_str());
183183
});
184184

185185
fn get_string<'a>(map: &'a json::Object, key: &String) -> Option<&'a str> {
@@ -205,20 +205,20 @@ fn run_color_tests(json_data: &str, to_json: |result: Option<Color>| -> json::Js
205205

206206
#[test]
207207
fn color3() {
208-
run_color_tests(include_str!("css-parsing-tests/color3.json"), |c| c.to_json())
208+
run_color_tests(include_str!("../css-parsing-tests/color3.json"), |c| c.to_json())
209209
}
210210

211211

212212
#[test]
213213
fn color3_hsl() {
214-
run_color_tests(include_str!("css-parsing-tests/color3_hsl.json"), |c| c.to_json())
214+
run_color_tests(include_str!("../css-parsing-tests/color3_hsl.json"), |c| c.to_json())
215215
}
216216

217217

218218
/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
219219
#[test]
220220
fn color3_keywords() {
221-
run_color_tests(include_str!("css-parsing-tests/color3_keywords.json"), |c| {
221+
run_color_tests(include_str!("../css-parsing-tests/color3_keywords.json"), |c| {
222222
match c {
223223
Some(RGBA(RGBA { red: r, green: g, blue: b, alpha: a }))
224224
=> vec!(r * 255., g * 255., b * 255., a).to_json(),
@@ -252,15 +252,15 @@ fn bench_color_lookup_fail(b: &mut test::Bencher) {
252252

253253
#[test]
254254
fn nth() {
255-
run_json_tests(include_str!("css-parsing-tests/An+B.json"), |input| {
255+
run_json_tests(include_str!("../css-parsing-tests/An+B.json"), |input| {
256256
parse_nth(tokenize(input).map(|(c, _)| c).collect::<Vec<ComponentValue>>().as_slice())
257257
});
258258
}
259259

260260

261261
#[test]
262262
fn serializer() {
263-
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
263+
run_json_tests(include_str!("../css-parsing-tests/component_value_list.json"), |input| {
264264
let component_values = tokenize(input).map(|(c, _)| c).collect::<Vec<ComponentValue>>();
265265
let serialized = component_values.iter().to_css();
266266
tokenize(serialized.as_slice()).map(|(c, _)| c).collect::<Vec<ComponentValue>>()
File renamed without changes.

0 commit comments

Comments
 (0)