// Copyright 2022 The GRADIS Project Contributors // SPDX-License-Identifier: Apache-2.0 // SPDX-FileContributor: Lucas Hinderberger // // Each abovementioned SPDX-FileContributor has contributed to and/or modified this file. // Please add your name and email address to the list above, if you publish modifications. // // 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 // // http://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. use std::str; use lazy_static::lazy_static; use gradiff::codec::{decode_from_str, encode_to_str, File, FileHeader, FormatVersion}; use gradiff::model::Diagram; const EMPTY_DIAGRAM_BYTES: &[u8] = include_bytes!("empty.gdff"); //REUSE-IgnoreStart lazy_static! { static ref EMPTY_DIAGRAM: File = File::new( FileHeader::new( Some(" Copyright 2022 The GRADIS Project Contributors\n SPDX-License-Identifier: CC0-1.0\n SPDX-FileContributor: Lucas Hinderberger \n\n Each abovementioned SPDX-FileContributor has contributed to and/or modified this file.\n Please add your name and email address to the list above, if you publish modifications.".to_string()), FormatVersion{major: 0, minor: 1} ), vec![] ); } //REUSE-IgnoreEnd #[test] fn empty_diagram_can_be_de_and_encoded() { let expected_encoded = str::from_utf8(EMPTY_DIAGRAM_BYTES).unwrap(); let actual_encoded = encode_to_str(&*EMPTY_DIAGRAM).unwrap(); let actual_decoded: File = decode_from_str(expected_encoded).unwrap(); assert_eq!(expected_encoded, actual_encoded); assert_eq!(&*EMPTY_DIAGRAM, &actual_decoded); for n in 1..10 { let actual_decoded_trailing_lfs: File = decode_from_str((expected_encoded.to_string() + "\n".repeat(n).as_str()).as_str()).unwrap(); assert_eq!(&*EMPTY_DIAGRAM, &actual_decoded_trailing_lfs); } } #[test] fn empty_diagram_is_processed_correctly() { let parsed_file: File = str::from_utf8(EMPTY_DIAGRAM_BYTES).unwrap().parse().unwrap(); let mut diagram = Diagram::new(); for chunk in parsed_file.chunks().iter() { for change in chunk.changes().iter() { diagram.apply_change(change).unwrap(); } } let view = diagram.view(); assert_eq!(view.objects().len(), 0); assert_eq!(view.dependent_object_ids().len(), 0); assert!(view.current_canvas_id().is_none()); assert!(view.current_canvas().is_none()); }