<commit_before>extern crate env_logger;
extern crate serde;
#[macro_use]
extern crate serde_derive;

extern crate gears;
use gears::dsl::command::*;
use gears::structure::common::{Document, DocumentList};

// partof: #TST-dsl-consistency

#[test]
fn test_dsl_tokens_to_tree() {
    let _ = env_logger::init();

    let tokens = vec![
        DslToken::With("domain".to_owned()),
        DslToken::BlockOpen,

        DslToken::With("entity post".to_owned()),
        DslToken::BlockOpen,

        DslToken::With("attibute name".to_owned()),
        DslToken::BlockOpen,

        DslToken::Comment("This adds a default value of 'zork'".to_owned()),
        DslToken::Command("add default 'zork'".to_owned()),

        DslToken::BlockClose,
        DslToken::BlockClose,
        DslToken::BlockClose,
    ];

    match tokens_as_tree(&tokens) {
        Ok(tree) => {
            assert_eq!(tree.len(), 1);
            match tree[0] {
                DslTree::Scope(ref e, ref v) => assert_eq!(e, "domain"),
                _ => assert!(false),
            }
        }
        Err(_) => {
            assert!(false);
        }
    }
}

use gears::dsl::command::{GearsDsl, DslTree, DslTokens};

#[derive(Debug, Serialize, Deserialize)]
struct Zork {
    pub grue: bool,
}

impl Default for Zork {
    fn default() -> Zork {
        Zork { grue: false }
    }
}

impl GearsDsl for Zork {
    fn generate_dsl(&self) -> DslTokens {
        unimplemented!();
    }

    fn consume_command(&mut self, s: &str) -> Result<(), String> {
        unimplemented!();
    }

    fn consume_scope(&mut self, s: &str, tree: &Vec<DslTree>) -> Result<(), String> {
        unimplemented!();
    }
}

type ZorkList = DocumentList<Zork>;

// partof: #TST-dsl-consistency-common_document_list
//
#[test]
fn test_dsl_document_list() {
    let _ = env_logger::init();


    let mut list = ZorkList::new();

    assert!(list.interpret_dsl("add itemone;").is_ok());
    assert_eq!(list.len(), 1);

    assert!(list.interpret_dsl("add itemtwo;").is_ok());
    assert_eq!(list.len(), 2);

    assert!(list.interpret_dsl("remove itemtwo;").is_ok());
    assert_eq!(list.len(), 1);

}

#[test]
fn test_dsl_document_list_multiline() {
    let _ = env_logger::init();


    let mut list = ZorkList::new();

    assert!(
        list.interpret_dsl(
            r#"
    add itemone;
    add itemtwo;
    add itemthree;
    "#,
        ).is_ok()
    );
    assert_eq!(list.len(), 3);

    assert!(
        list.interpret_dsl(
            r#"
    remove itemone;
    remove itemtwo;
    remove itemthree;
    add newitemone;
    "#,
        ).is_ok()
    );
    assert_eq!(list.len(), 1);

}
<commit_msg>test: Add test for multi-line dsl regeneration<commit_after>extern crate env_logger;
extern crate serde;
#[macro_use]
extern crate serde_derive;

extern crate gears;
use gears::dsl::command::*;
use gears::structure::common::{Document, DocumentList};

// partof: #TST-dsl-consistency

#[test]
fn test_dsl_tokens_to_tree() {
    let _ = env_logger::init();

    let tokens = vec![
        DslToken::With("domain".to_owned()),
        DslToken::BlockOpen,

        DslToken::With("entity post".to_owned()),
        DslToken::BlockOpen,

        DslToken::With("attibute name".to_owned()),
        DslToken::BlockOpen,

        DslToken::Comment("This adds a default value of 'zork'".to_owned()),
        DslToken::Command("add default 'zork'".to_owned()),

        DslToken::BlockClose,
        DslToken::BlockClose,
        DslToken::BlockClose,
    ];

    match tokens_as_tree(&tokens) {
        Ok(tree) => {
            assert_eq!(tree.len(), 1);
            match tree[0] {
                DslTree::Scope(ref e, ref v) => assert_eq!(e, "domain"),
                _ => assert!(false),
            }
        }
        Err(_) => {
            assert!(false);
        }
    }
}

use gears::dsl::command::{GearsDsl, DslTree, DslTokens};

#[derive(Debug, Serialize, Deserialize)]
struct Zork {
    pub grue: bool,
}

impl Default for Zork {
    fn default() -> Zork {
        Zork { grue: false }
    }
}

impl GearsDsl for Zork {
    fn generate_dsl(&self) -> DslTokens {
        DslTokens::new()
    }

    fn consume_command(&mut self, s: &str) -> Result<(), String> {
        unimplemented!();
    }

    fn consume_scope(&mut self, s: &str, tree: &Vec<DslTree>) -> Result<(), String> {
        unimplemented!();
    }
}

type ZorkList = DocumentList<Zork>;

// partof: #TST-dsl-consistency-common_document_list
//
#[test]
fn test_dsl_document_list() {
    let _ = env_logger::init();


    let mut list = ZorkList::new();

    assert!(list.interpret_dsl("add itemone;").is_ok());
    assert_eq!(list.len(), 1);

    assert!(list.interpret_dsl("add itemtwo;").is_ok());
    assert_eq!(list.len(), 2);

    assert!(list.interpret_dsl("remove itemtwo;").is_ok());
    assert_eq!(list.len(), 1);

}

#[test]
fn test_dsl_document_list_multiline() {
    let _ = env_logger::init();


    let mut list = ZorkList::new();

    assert!(
        list.interpret_dsl(
            r#"
    add itemone;
    add itemtwo;
    add itemthree;
    "#,
        ).is_ok()
    );
    assert_eq!(list.len(), 3);

    assert!(
        list.interpret_dsl(
            r#"
    remove itemone;
    remove itemtwo;
    remove itemthree;
    add newitemone;
    "#,
        ).is_ok()
    );
    assert_eq!(list.len(), 1);

}

#[test]
fn test_dsl_document_list_multiline_regenerate() {
    let _ = env_logger::init();


    let mut list = ZorkList::new();

    assert!(
        list.interpret_dsl(
            r#"
    add itemone;
    add itemtwo;
    add itemthree;
    remove itemthree;
    "#,
        ).is_ok()
    );
    assert_eq!(list.len(), 2);

    let mut list_b = ZorkList::new();
    list_b.consume_dsl(&list.generate_dsl());

    assert_eq!(list.generate_dsl(), list_b.generate_dsl());

}

{'fraction_non_alphanumeric': 0.1607876712328767, 'fraction_numerical': 0.0025684931506849314, 'mean_word_length': 2.6055555555555556, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7203252', 'n_tokens_mistral': 2077, 'n_tokens_neox': 2017, 'n_words': 384}