Skip to content

Commit 8f860fd

Browse files
committed
Format src/lib.rs
1 parent ac16188 commit 8f860fd

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

src/lib.rs

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ mod read_string;
2525
mod remainder;
2626
mod suitable_seekable_buffered_bytes_stream;
2727
mod suitable_seekable_buffered_text_stream;
28-
mod suitable_unseekable_buffered_bytes_stream;
29-
mod suitable_unseekable_buffered_text_stream;
3028
mod suitable_stream;
3129
mod suitable_unbuffered_bytes_stream;
3230
mod suitable_unbuffered_text_stream;
31+
mod suitable_unseekable_buffered_bytes_stream;
32+
mod suitable_unseekable_buffered_text_stream;
3333
mod utf8_char_source;
3434

3535
mod char_or_eof;
3636
use crate::char_or_eof::CharOrEof;
3737
use CharOrEof::{Char, Eof};
3838

3939
mod unicode_utils;
40-
use crate::unicode_utils::{is_surrogate, decode_surrogate_pair, UnicodeError};
40+
use crate::unicode_utils::{decode_surrogate_pair, is_surrogate, UnicodeError};
4141

4242
use crate::suitable_stream::BufferingMode;
4343

@@ -123,7 +123,7 @@ impl IntoPy<PyObject> for TokenType {
123123
}
124124

125125
#[derive(Error, Debug)]
126-
pub enum ParsingError {
126+
pub enum ParsingError {
127127
#[error("{0}")]
128128
InvalidJson(String),
129129
#[error("Error due to limitation: {0}")]
@@ -372,7 +372,7 @@ impl RustTokenizer {
372372
"Invalid JSON character: {c:?}"
373373
)));
374374
}
375-
},
375+
}
376376
Eof => (),
377377
},
378378
State::Integer => match c {
@@ -721,41 +721,37 @@ impl RustTokenizer {
721721
}
722722
}
723723
}
724-
State::UnicodeSurrogateStart => {
725-
match c {
726-
Char('\\') => {
727-
slf.next_state = State::UnicodeSurrogateStringEscape;
728-
}
729-
Char(_) => {
730-
return Err(ParsingError::InvalidJson(format!(
731-
"Unpaired UTF-16 surrogate"
732-
)));
733-
}
734-
Eof => {
735-
return Err(ParsingError::InvalidJson(format!(
736-
"Unpaired UTF-16 surrogate at end of file"
737-
)));
738-
}
724+
State::UnicodeSurrogateStart => match c {
725+
Char('\\') => {
726+
slf.next_state = State::UnicodeSurrogateStringEscape;
739727
}
740-
}
741-
State::UnicodeSurrogateStringEscape => {
742-
match c {
743-
Char('u') => {
744-
slf.unicode_buffer = CompactString::with_capacity(4);
745-
slf.next_state = State::UnicodeSurrogate;
746-
}
747-
Char(_) => {
748-
return Err(ParsingError::InvalidJson(format!(
749-
"Unpaired UTF-16 surrogate"
750-
)));
751-
}
752-
Eof => {
753-
return Err(ParsingError::InvalidJson(format!(
754-
"Unpaired UTF-16 surrogate at end of file"
755-
)));
756-
}
728+
Char(_) => {
729+
return Err(ParsingError::InvalidJson(format!(
730+
"Unpaired UTF-16 surrogate"
731+
)));
757732
}
758-
}
733+
Eof => {
734+
return Err(ParsingError::InvalidJson(format!(
735+
"Unpaired UTF-16 surrogate at end of file"
736+
)));
737+
}
738+
},
739+
State::UnicodeSurrogateStringEscape => match c {
740+
Char('u') => {
741+
slf.unicode_buffer = CompactString::with_capacity(4);
742+
slf.next_state = State::UnicodeSurrogate;
743+
}
744+
Char(_) => {
745+
return Err(ParsingError::InvalidJson(format!(
746+
"Unpaired UTF-16 surrogate"
747+
)));
748+
}
749+
Eof => {
750+
return Err(ParsingError::InvalidJson(format!(
751+
"Unpaired UTF-16 surrogate at end of file"
752+
)));
753+
}
754+
},
759755
State::UnicodeSurrogate => {
760756
match c {
761757
Char(c) => {
@@ -786,13 +782,12 @@ impl RustTokenizer {
786782
"This should never happen, please report it as a bug..."
787783
)));
788784
};
789-
c = Char(
790-
decode_surrogate_pair(prev_charcode, charcode)
791-
.map_err(|_| ParsingError::InvalidJson(format!(
785+
c = Char(decode_surrogate_pair(prev_charcode, charcode).map_err(|_| {
786+
ParsingError::InvalidJson(format!(
792787
"Error decoding UTF-16 surrogate pair \
793788
\\u{prev_charcode:x}\\u{charcode:x}"
794-
)))?
795-
);
789+
))
790+
})?);
796791
slf.prev_charcode = None;
797792
slf.next_state = State::String_;
798793
add_char = true;

tests/test_using_json_stream_tokenizer_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
import pytest
77

8-
from json_stream.tests.test_tokenizer import TestJsonTokenization
8+
from json_stream.tokenizer.tests.test_tokenizer import TestJsonTokenization
99
from json_stream.tests.test_buffering import TestBuffering
1010
from json_stream_rs_tokenizer import RustTokenizer
1111

1212

1313
@pytest.fixture(autouse=True, scope="module")
1414
def override_tokenizer():
15-
with patch("json_stream.tests.test_tokenizer.tokenize", RustTokenizer):
15+
with patch(
16+
"json_stream.tokenizer.tests.test_tokenizer.tokenize", RustTokenizer
17+
), patch("json_stream.tests.test_buffering.tokenize", RustTokenizer):
1618
yield
1719

1820

0 commit comments

Comments
 (0)