Repository: DioxusLabs/dioxus
File: packages/rsx/src/ifmt.rs (Rust)

Code before:
                }),
                Segment::Literal(" ".to_string()),
                Segment::Formatted(FormattedSegment {
                    format_args: String::new(),
                    segment: FormattedSegmentType::Ident(Ident::new("def", Span::call_site()))
                }),
            ]
        );
    }

    #[test]
    fn printing_raw() {
        let input = syn::parse2::<IfmtInput>(quote! { "hello {world}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        let input = syn::parse2::<IfmtInput>(quote! { "hello {world} {world} {world}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        let input = syn::parse2::<IfmtInput>(quote! { "hello {world} {world} {world()}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        // raw expressions are always static!
        let input =
            syn::parse2::<IfmtInput>(quote! { r#"hello {world} {world} {world()}"# }).unwrap();
        println!("{}", input.to_string_with_quotes());
        assert!(input.is_static());

        let input = syn::parse2::<IfmtInput>(quote! { r#"hello"# }).unwrap();
        println!("{}", input.to_string_with_quotes());
        assert!(input.is_static());
    }

    #[test]
    fn to_static() {
        let input = syn::parse2::<IfmtInput>(quote! { "body {{ background: red; }}" }).unwrap();
        assert_eq!(
            input.to_static(),
            Some("body { background: red; }".to_string())
        );
    }

    #[test]
    fn raw_blocks_not_formatted() {
        let input = syn::parse2::<IfmtInput>(quote! { r#"hello {}"# }).unwrap();
        println!("{}", input.to_string_with_quotes());
        assert_eq!(input.to_string_with_quotes(), "r#\"hello {}\"#".to_string());
    }
}


Review comment (bug):
This seems wrong... The input has a bunch of dynamic segments. It shouldn't be static. The format macro allows formatted segments in raw text: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=91f1e2b6c1835a0eaf97ec8154b7162f

Code after:
                }),
            ]
        );
    }

    #[test]
    fn printing_raw() {
        let input = syn::parse2::<IfmtInput>(quote! { "hello {world}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        let input = syn::parse2::<IfmtInput>(quote! { "hello {world} {world} {world}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        let input = syn::parse2::<IfmtInput>(quote! { "hello {world} {world} {world()}" }).unwrap();
        println!("{}", input.to_string_with_quotes());

        let input =
            syn::parse2::<IfmtInput>(quote! { r#"hello {world} {world} {world()}"# }).unwrap();
        println!("{}", input.to_string_with_quotes());
        assert!(!input.is_static());

        let input = syn::parse2::<IfmtInput>(quote! { r#"hello"# }).unwrap();
        println!("{}", input.to_string_with_quotes());
        assert!(input.is_static());
    }

    #[test]
    fn to_static() {
        let input = syn::parse2::<IfmtInput>(quote! { "body {{ background: red; }}" }).unwrap();
        assert_eq!(
            input.to_static(),
            Some("body { background: red; }".to_string())
        );
    }
}