Skip to content

Commit 08f4014

Browse files
committed
test(linter): Add more tests for deserializing globals in Oxlintrc. (#16858)
Just ensuring they work correctly by checking that they get mapped to the correct enum variants. - `readonly`/`readable`/`false` should map to Readonly - `writable`/`writeable`/`true` should map to Writable - `off` should map to Off
1 parent 7510414 commit 08f4014

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

crates/oxc_linter/src/config/globals.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ mod test {
155155
assert!(globals.is_enabled("foo"));
156156
assert!(globals.is_enabled("bar"));
157157
assert!(!globals.is_enabled("baz"));
158+
159+
assert_eq!(globals.get("foo"), Some(&GlobalValue::Readonly));
160+
assert_eq!(globals.get("bar"), Some(&GlobalValue::Writable));
161+
assert_eq!(globals.get("baz"), Some(&GlobalValue::Off));
158162
}
159163

160164
#[test]
@@ -165,6 +169,9 @@ mod test {
165169
});
166170
assert!(globals.is_enabled("foo"));
167171
assert!(globals.is_enabled("bar"));
172+
// Ensure they map to the correct variants
173+
assert_eq!(globals.get("foo"), Some(&GlobalValue::Readonly));
174+
assert_eq!(globals.get("bar"), Some(&GlobalValue::Writable));
168175
}
169176

170177
#[test]
@@ -175,6 +182,9 @@ mod test {
175182
});
176183
assert!(globals.is_enabled("foo"));
177184
assert!(globals.is_enabled("bar"));
185+
186+
assert_eq!(globals.get("foo"), Some(&GlobalValue::Writable));
187+
assert_eq!(globals.get("bar"), Some(&GlobalValue::Readonly));
178188
}
179189

180190
#[test]

crates/oxc_linter/src/config/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ mod test {
105105
);
106106
assert_eq!(env.iter().count(), 1);
107107
assert!(globals.is_enabled("foo"));
108+
assert_eq!(globals.get("foo"), Some(&super::GlobalValue::Readonly));
109+
}
110+
111+
#[test]
112+
fn test_deserialize_globals() {
113+
let config = Oxlintrc::deserialize(&serde_json::json!({
114+
"globals": {
115+
"foo": "readable",
116+
"bar": "writeable",
117+
"baz": "off",
118+
"qux": true,
119+
"quux": false,
120+
"corge": "readonly",
121+
"grault": "writable"
122+
}
123+
}));
124+
assert!(config.is_ok());
125+
126+
let Oxlintrc { globals, .. } = config.unwrap();
127+
assert!(globals.is_enabled("foo"));
128+
assert!(globals.is_enabled("bar"));
129+
// Ensure they map to the correct variants
130+
assert_eq!(globals.get("foo"), Some(&super::GlobalValue::Readonly));
131+
assert_eq!(globals.get("bar"), Some(&super::GlobalValue::Writable));
132+
assert_eq!(globals.get("baz"), Some(&super::GlobalValue::Off));
133+
assert_eq!(globals.get("qux"), Some(&super::GlobalValue::Writable));
134+
assert_eq!(globals.get("quux"), Some(&super::GlobalValue::Readonly));
135+
assert_eq!(globals.get("corge"), Some(&super::GlobalValue::Readonly));
136+
assert_eq!(globals.get("grault"), Some(&super::GlobalValue::Writable));
108137
}
109138

110139
#[test]

0 commit comments

Comments
 (0)