blob: ab5a1c9933f82ed2462e3610a780386e0072117a [file]
# Copyright 2025 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Tests parsing a sized-entry ring buffer."""
import unittest
from pw_containers import var_len_entry_queue
class TestEncodeTokenized(unittest.TestCase):
def test_one_entry(self) -> None:
self.assertEqual(
list(var_len_entry_queue.parse(b'?\0041234?890', 1, 6)),
[b'1234'],
)
def test_two_entries(self) -> None:
self.assertEqual(
list(var_len_entry_queue.parse(b'?\00212\00234?90', 1, 7)),
[b'12', b'34'],
)
def test_two_entries_wrapped(self) -> None:
self.assertEqual(
list(var_len_entry_queue.parse(b'4\00212?x\004123', 6, 4)),
[b'1234', b'12'],
)
if __name__ == '__main__':
unittest.main()