Skip to content

Commit

Permalink
fix: Update tests to reflect the fact that - is no longer parsed as…
Browse files Browse the repository at this point in the history
… the end of array
  • Loading branch information
jshearer committed Oct 27, 2023
1 parent 780df98 commit 4ae50a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions crates/doc/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ impl Pointer {
/// ```
/// use doc::ptr::{Pointer, Token};
///
/// let pointer = Pointer::from_str("/foo/ba~1ar/3/-");
/// let pointer = Pointer::from_str("/foo/ba~1ar/3");
/// let expected_tokens = vec![
/// Token::Property("foo".to_string()),
/// Token::Property("ba/ar".to_string()),
/// Token::Index(3),
/// Token::NextIndex,
/// ];
/// assert_eq!(expected_tokens, pointer.0);
/// ```
Expand Down Expand Up @@ -362,12 +361,11 @@ mod test {
use Token::*;

// Basic example.
let ptr = Pointer::from("/p1/2/p3/-");
let ptr = Pointer::from("/p1/2/p3");
assert!(vec![
Property("p1".to_string()),
Index(2),
Property("p3".to_string()),
NextIndex
Property("p3".to_string())
]
.iter()
.eq(ptr.iter()));
Expand All @@ -392,13 +390,12 @@ mod test {
);

// Handles disallowed integer representations.
let ptr = Pointer::from("/01/+2/-3/4/-");
let ptr = Pointer::from("/01/+2/-3/4");
assert!(vec![
Property("01".to_string()),
Property("+2".to_string()),
Property("-3".to_string()),
Index(4),
NextIndex,
Index(4)
]
.iter()
.eq(ptr.iter()));
Expand Down Expand Up @@ -490,10 +487,9 @@ mod test {
("/foo/2/a", json!("hello")),
// Add property to existing object.
("/foo/2/b", json!(3)),
("/foo/0", json!(false)), // Update existing Null.
("/bar", json!(null)), // Add property to doc root.
("/foo/0", json!(true)), // Update from 'false'.
("/foo/-", json!("world")), // NextIndex extends Array.
("/foo/0", json!(false)), // Update existing Null.
("/bar", json!(null)), // Add property to doc root.
("/foo/0", json!(true)), // Update from 'false'.
// Index token is interpreted as property because object exists.
("/foo/2/4", json!(5)),
// NextIndex token is also interpreted as property.
Expand All @@ -510,7 +506,7 @@ mod test {
}

let expect = json!({
"foo": [true, null, {"-": false, "a": "hello", "b": 3, "4": 5}, "world"],
"foo": [true, null, {"-": false, "a": "hello", "b": 3, "4": 5}],
"bar": null,
});

Expand Down
2 changes: 1 addition & 1 deletion crates/doc/src/shape/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mod test {
(&arr1, "/3", ("addl-item", Exists::May)),
(&arr1, "/9", ("addl-item", Exists::May)),
(&arr1, "/10", ("addl-item", Exists::Cannot)),
(&arr1, "/-", ("addl-item", Exists::Cannot)),
(&arr1, "/-", ("<missing>", Exists::Cannot)),
(&arr2, "/0", ("0", Exists::May)),
(&arr2, "/1", ("1", Exists::May)),
(&arr2, "/123", ("<missing>", Exists::Implicit)),
Expand Down

0 comments on commit 4ae50a5

Please sign in to comment.