swrs 0.1.1

A simple rust library that reads and parses a sketchware project
Documentation
use swrs::parser::Parsable;
use swrs::parser::view::models::AndroidView;
use swrs::parser::view::View;

#[test]
fn parse_android_view() {
    let input = r#"{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear_title","image":{"resName":"default_image","rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":-1,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":0,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"linear_title","preIndex":0,"preParent":"root","preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}"#;

    match AndroidView::parse(input) {
        Ok(_) => (),
        Err(err) => panic!("Failed to parse android view: {:?}", err)
    };

    // todo: check this bruh
}

#[test]
fn parse_view() {
    let input = r#"@main.xml
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"vscroll1","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":8,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":1,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"vscroll1","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":12}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"vscroll2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":8,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":1,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"vscroll2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":12}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear1","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"vscroll1","parentType":12,"preId":"linear1","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"textview2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear1","parentType":0,"preId":"textview2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"CPU Info","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"cpuinfo","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear1","parentType":0,"preId":"","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"TextView","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"vscroll2","parentType":12,"preId":"linear2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"textview3","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear2","parentType":0,"preId":"textview3","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"RAM Info","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"raminfo","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear2","parentType":0,"preId":"","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"TextView","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}

@main.xml_fab
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"_fab","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":85,"marginBottom":16,"marginLeft":16,"marginRight":16,"marginTop":16,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":0,"weightSum":0,"width":-2},"max":100,"parentType":-1,"preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":16}"#;

    match View::parse(input) {
        Ok(_) => (),
        Err(err) => panic!("Failed to parse view: {:?}", err)
    }

    // todo: check this bruh
}

#[test]
fn reconstruct_android_view() {
    let input = r#"{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear_title","image":{"resName":"default_image","rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":-1,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":0,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"linear_title","preIndex":0,"preParent":"root","preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}"#;

    let parsed = match AndroidView::parse(input) {
        Ok(r) => r,
        Err(err) => panic!("Failed to parse android view: {:?}", err)
    };

    let reconstructed = parsed.reconstruct().expect("Failed to reconstruct android view");
    assert_eq!(input, reconstructed);
}

#[test]
fn reconstruct_view() {
    let input = r#"@main.xml
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"vscroll1","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":8,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":1,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"vscroll1","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":12}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"vscroll2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":8,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":1,"weightSum":0,"width":-1},"max":100,"parent":"root","parentType":0,"preId":"vscroll2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":12}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear1","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"vscroll1","parentType":12,"preId":"linear1","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"textview2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear1","parentType":0,"preId":"textview2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"CPU Info","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"cpuinfo","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear1","parentType":0,"preId":"","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"TextView","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"linear2","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-1},"max":100,"parent":"vscroll2","parentType":12,"preId":"linear2","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":0}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"textview3","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear2","parentType":0,"preId":"textview3","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"RAM Info","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"raminfo","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":1,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"marginTop":0,"orientation":-1,"paddingBottom":8,"paddingLeft":8,"paddingRight":8,"paddingTop":8,"weight":0,"weightSum":0,"width":-2},"max":100,"parent":"linear2","parentType":0,"preId":"","preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"TextView","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":4}

@main.xml_fab
{"adSize":"","adUnitId":"","alpha":1.0,"checked":0,"choiceMode":0,"clickable":1,"customView":"","dividerHeight":1,"enabled":1,"firstDayOfWeek":1,"id":"_fab","image":{"rotate":0,"scaleType":"CENTER"},"indeterminate":"false","index":0,"layout":{"backgroundColor":16777215,"gravity":0,"height":-2,"layoutGravity":85,"marginBottom":16,"marginLeft":16,"marginRight":16,"marginTop":16,"orientation":-1,"paddingBottom":0,"paddingLeft":0,"paddingRight":0,"paddingTop":0,"weight":0,"weightSum":0,"width":-2},"max":100,"parentType":-1,"preIndex":0,"preParentType":0,"progress":0,"progressStyle":"?android:progressBarStyle","scaleX":1.0,"scaleY":1.0,"spinnerMode":1,"text":{"hint":"","hintColor":-10453621,"imeOption":0,"inputType":1,"line":0,"singleLine":0,"text":"","textColor":-16777216,"textFont":"default_font","textSize":12,"textType":0},"translationX":0.0,"translationY":0.0,"type":16}"#;

    let parsed = match View::parse(input) {
        Ok(r) => r,
        Err(err) => panic!("Failed to parse view: {:?}", err)
    };

    let reconstructed = parsed.reconstruct().expect("Failed to reconstruct view");

    assert_eq!(reconstructed, input);
}