idl 0.1.1

Library used for the idl language.
Documentation
use super::StorageItem;

pub static IDL_PROTOCOL_TEST: &str = r#"/// GENERATED CODE
/// Use `idl language test --generate-files` for update.

library IdlProtocolTest;

struct Point {
    x: int,
    y: int,
}

enum Colors {
    Red,
    Blue,
    Green,
    Yellow,
}

enum Types {
    First: string,
    Second: float,
}

/// Test for all primitive types.
interface TypeFeedback {
    /// Sends an array of integer values, and it must return a stream with the same length.
    streamTest: (input: int[]) -> stream int,
    
    /// Must return the same `bool` value.
    boolTest: (input: bool) -> bool,

    /// Must return the same `string` value.
    stringTest: (input: string) -> string,

    /// Must return the same `int` value.
    intTest: (input: int) -> int,

    /// Must return the same `float` value.
    floatTest: (input: float) -> float,

    /// Must return the same `Colors` value.
    enumTest: (input: Colors) -> Colors,

    /// Must return the same `Types` value.
    typeEnumTest: (input: Types) -> Types,

    /// Must return the same map value.
    mapWithIntIndex: (input: string[int]) -> string[int],

    /// Must return the same map value.
    mapWithStringIndex: (input: int[string]) -> int[string],

    /// Must return the same array value.
    boolArray: (input: bool[]) -> bool[],

    /// Must return the same array value.
    stringArray: (input: string[]) -> string[],

    /// Must return the same array value.
    bytesArray: (input: byte[]) -> byte[],

    /// Must return the same array value.
    intArray: (input: int[]) -> int[],

    /// Must return the same array value.
    floatArray: (input: float[]) -> float[],

    /// Must return the same array value.
    enumArray: (input: Colors[]) -> Colors[],

    /// Must return the same array value.
    typeEnumArray: (input: Types[]) -> Types[],

    /// Must return the same array value.
    arrayOfintArray: (input: int[][]) -> int[][],
}

/// Text processing category.
interface TextProcessing {
    /// https://rosettacode.org/wiki/Increment_a_numerical_string
    /// 
    /// Assume ASCII string.
    incrementNumericalString: (input: string) -> string,
    
    /// When two or more words are composed of the same characters, 
    /// but in a different order, they are called anagrams.
    /// https://rosettacode.org/wiki/Anagrams
    /// 
    /// Must return a sorted list of anagrams.
    /// Assume Unicode string.
    anagrams: (input: string[]) -> string[][],
    
    /// Find and display all the ordered words that have the longest word length.
    /// https://rosettacode.org/wiki/Ordered_words
    /// 
    /// Assume ASCII string.
    orderedWords: (input: string[]) -> string[],

    /// Find the index of a string (needle) in an indexable, ordered collection of strings (haystack).
    /// https://rosettacode.org/wiki/Search_a_list
    /// 
    /// Return the first occurrence.
    /// Assume ASCII string.
    searchOccurrence: (haystack: string[], needle: string) -> int?,
}

/// String manipulation category.
interface StringManipulation {
    /// Create a boolean function which takes in a string and tells whether it is a numeric 
    /// string (floating point and negative numbers included) in the syntax the language uses 
    /// for numeric literals or numbers converted from strings.
    /// https://rosettacode.org/wiki/Determine_if_a_string_is_numeric
    isNumericString: (input: string) -> bool,

    /// Return a substring starting from n characters in and of m length;
    /// https://rosettacode.org/wiki/Substring
    /// 
    /// Assume Unicode scalar values.
    substring: (input: string, n: int, m: int) -> string,        

    /// Find the character length of a string.    
    /// https://rosettacode.org/wiki/String_length
    /// 
    /// Assume Unicode scalar values.
    stringLength: (input: string) -> int,

    /// Take a string and reverse it.
    /// https://rosettacode.org/wiki/Reverse_a_string
    /// 
    /// Assume Unicode scalar values.
    reverseString: (input: string) -> string,

    /// Make the entire string uppercase.
    /// 
    /// Assume ASCII string.
    uppercase: (input: string) -> string,

    /// Make the entire string lowercase.
    /// 
    /// Assume ASCII string.
    lowercase: (input: string) -> string,

    /// Trim the string.
    /// 
    /// Assume ASCII string.
    trim: (input: string) -> string,
}

/// Arithmetic operations and discrete math categories.
interface MathOperations {
    /// Given non-negative integers m and n, generate all size m combinations
    /// of the integers from 0 (zero) to n-1 in sorted order 
    /// (each combination is sorted and the entire table is sorted).
    /// https://rosettacode.org/wiki/Combinations
    combinations: (input: int[], k: int) -> int[][],

    /// Write a program that generates all permutations of n different objects.
    /// https://rosettacode.org/wiki/Permutations
    permutations: (n: int) -> int[][],

    /// Write a function to generate the nth Fibonacci number.
    /// https://rosettacode.org/wiki/Fibonacci_sequence
    /// 
    /// Support for negative values is not necessary.
    fibonacciSequence: (n: int) -> int,
}"#;

pub static IDS_PROTOCOL_TEST: &str = r#"/// GENERATED CODE
/// Use `idl language test --generate-files` for update.

package IdlProtocolTest {
    idl: 1,
    version: 1,
}

server Main {
    language: "rust",
    layers: [ws],
}"#;

pub fn create_new_module_for_test() -> StorageItem {
    let mut result = vec![];

    result.push(StorageItem::Folder {
        name: ".idl".to_owned(),
        items: vec![],
    });

    result.push(StorageItem::Source {
        name: ".gitignore".to_owned(),
        txt: "".to_owned(),
    });

    result.push(StorageItem::Source {
        name: "idl_protocol_test.ids".to_owned(),
        txt: IDS_PROTOCOL_TEST.to_owned(),
    });

    result.push(StorageItem::Source {
        name: "idl_protocol_test.idl".to_owned(),
        txt: IDL_PROTOCOL_TEST.to_owned(),
    });

    return StorageItem::Folder {
        name: "idl_protocol_test".to_owned(),
        items: result,
    };
}