map equality is independent of order
This commit is contained in:
parent
6138efc059
commit
57562b52d3
@ -1,3 +1,5 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use codemap::Span;
|
||||
|
||||
use crate::{args::FuncArgs, scope::Scope, Token};
|
||||
@ -10,6 +12,12 @@ pub(crate) struct Function {
|
||||
pos: Span,
|
||||
}
|
||||
|
||||
impl Hash for Function {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.pos.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Function {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.pos == other.pos
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
hash::{Hash, Hasher},
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
@ -29,6 +30,12 @@ pub(crate) struct Builtin(
|
||||
usize,
|
||||
);
|
||||
|
||||
impl Hash for Builtin {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.1.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
pub fn new(body: fn(CallArgs, &mut Parser<'_>) -> SassResult<Value>) -> Builtin {
|
||||
let count = FUNCTION_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||
|
@ -27,7 +27,7 @@ use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||
|
||||
mod name;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
pub(crate) struct Color {
|
||||
rgba: Rgba,
|
||||
hsla: Option<Hsla>,
|
||||
@ -65,7 +65,7 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
struct Rgba {
|
||||
red: Number,
|
||||
green: Number,
|
||||
@ -88,7 +88,7 @@ impl Rgba {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
struct Hsla {
|
||||
hue: Number,
|
||||
saturation: Number,
|
||||
|
@ -61,7 +61,7 @@ impl Op {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub(crate) enum QuoteKind {
|
||||
Quoted,
|
||||
None,
|
||||
@ -77,13 +77,13 @@ impl Display for QuoteKind {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum Brackets {
|
||||
None,
|
||||
Bracketed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum ListSeparator {
|
||||
Space,
|
||||
Comma,
|
||||
|
@ -7,7 +7,7 @@ pub(crate) use conversion::UNIT_CONVERSION_TABLE;
|
||||
|
||||
mod conversion;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(crate) enum Unit {
|
||||
// Absolute units
|
||||
/// Pixels
|
||||
@ -122,7 +122,7 @@ pub(crate) enum UnitKind {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(crate) struct DivUnit {
|
||||
numer: Unit,
|
||||
denom: Unit,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{slice::Iter, vec::IntoIter};
|
||||
use std::{collections::HashSet, slice::Iter, vec::IntoIter};
|
||||
|
||||
use crate::{
|
||||
common::{Brackets, ListSeparator},
|
||||
@ -6,9 +6,19 @@ use crate::{
|
||||
value::Value,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub(crate) struct SassMap(Vec<(Value, Value)>);
|
||||
|
||||
impl PartialEq for SassMap {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let set_one: HashSet<&Value> = self.0.iter().map(|(v1, _)| v1).collect();
|
||||
let set_two: HashSet<&Value> = other.0.iter().map(|(v1, _)| v1).collect();
|
||||
set_one == set_two
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for SassMap {}
|
||||
|
||||
impl SassMap {
|
||||
pub const fn new() -> SassMap {
|
||||
SassMap(Vec::new())
|
||||
|
@ -24,7 +24,7 @@ mod number;
|
||||
mod sass_function;
|
||||
|
||||
// todo: remove Eq and PartialEq impls
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum Value {
|
||||
Important,
|
||||
True,
|
||||
|
@ -16,7 +16,7 @@ mod integer;
|
||||
|
||||
const PRECISION: usize = 10;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Ord)]
|
||||
#[derive(Clone, Eq, PartialEq, Ord, Hash)]
|
||||
pub(crate) enum Number {
|
||||
Small(Rational64),
|
||||
Big(Box<BigRational>),
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
///
|
||||
/// The function name is stored in addition to the body
|
||||
/// for use in the builtin function `inspect()`
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Hash)]
|
||||
pub(crate) enum SassFunction {
|
||||
Builtin(Builtin, Identifier),
|
||||
UserDefined(Box<Function>, Identifier),
|
||||
|
@ -184,6 +184,11 @@ test!(
|
||||
);
|
||||
test!(
|
||||
map_merge_not_exactly_equal,
|
||||
"a {\n color: inspect(map-merge((0cm: a), (0mm: b)));;\n}\n",
|
||||
"a {\n color: inspect(map-merge((0cm: a), (0mm: b)));\n}\n",
|
||||
"a {\n color: (0cm: b);\n}\n"
|
||||
);
|
||||
test!(
|
||||
map_equality_is_independent_of_order,
|
||||
"a {\n color: (c: d, a: b)==(a: b, c: d);\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user