/*
 * Copyright 2022 Fluence Labs Limited
 *
 * 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.
 */

#![deny(
    dead_code,
    nonstandard_style,
    unused_imports,
    unused_mut,
    unused_variables,
    unused_unsafe,
    unreachable_patterns
)]

mod beautifier;

use crate::{beautify, beautify_to_string, BeautifyError};

#[test]
fn beautify_valid() {
    let air_script = "(seq (null) (null))";
    let mut buffer = vec![];
    let res = beautify(air_script, &mut buffer);
    assert!(matches!(res, Ok(())));
    assert_eq!(std::str::from_utf8(&buffer).unwrap(), "null\nnull\n");
}

#[test]
fn beautify_invalid() {
    let air_script = "(seq (null))";
    let mut buffer = vec![];
    let res = beautify(air_script, &mut buffer);
    assert!(matches!(res, Err(BeautifyError::Parse(_))));
}

#[test]
fn beautify_to_string_valid() {
    let air_script = "(seq (null) (null))";
    let res = beautify_to_string(air_script).unwrap();
    assert_eq!(res, "null\nnull\n");
}

#[test]
fn beautify_to_string_invalid() {
    let air_script = "(seq (null))";
    let res = beautify_to_string(air_script);
    assert!(matches!(res, Err(_)));
}
