Exemple #1
0
def test_select_conflict():
    arg_types = ftl_to_types("""
        bar = { $arg ->
             [0]  Zero
            *[Hello]   Hi
         }
    """)
    assert arg_types == {
        'bar': {
            'arg': Conflict(
                types=[
                    InferredType(
                        type=Number,
                        evidences=[
                            FakeFtlSource('bar', 2, 7),
                        ]
                    ),
                    InferredType(
                        type=String,
                        evidences=[
                            FakeFtlSource('bar', 3, 7),
                        ]
                    )
                ],
                message_source=FakeFtlSource('bar', 1, 1),
            )
        }
    }
Exemple #2
0
def test_conflicting_called_message():
    arg_types = ftl_to_types("""
        bar = { foo } { NUMBER($name) }
        foo = Hello { $name }
    """)
    assert arg_types['foo'] == {
        'name': InferredType(
            type=String,
            evidences=[FakeFtlSource('foo', 2, 15)]
        ),
    }

    assert type(arg_types['bar']['name']) == Conflict
    assert len(arg_types['bar']['name'].types) == 2
    assert arg_types['bar']['name'].types[0] == InferredType(
        type=String,
        evidences=[
            FakeFtlSource('bar', 1, 9),  # We are calling foo
            FakeFtlSource('foo', 2, 15),  # foo thinks 'name' is String
        ],
    )
    assert arg_types['bar']['name'].types[1] == InferredType(
        type=Number,
        evidences=[
            FakeFtlSource('bar', 1, 17),  # NUMBER call
        ],
    )
Exemple #3
0
def test_called_message():
    arg_types = ftl_to_types("""
        bar = { foo }
        foo = Hello { $name }, you have { NUMBER($count) } emails.
    """)
    assert arg_types['foo'] == {
        'name': InferredType(
            type=String,
            evidences=[FakeFtlSource('foo', 2, 15)]
        ),
        'count': InferredType(
            type=Number,
            evidences=[FakeFtlSource('foo', 2, 35)]
        ),
    }

    assert arg_types['bar'] == {
        'name': InferredType(
            type=String,
            evidences=[
                FakeFtlSource('bar', 1, 9),  # We are calling foo
                FakeFtlSource('foo', 2, 15),  # foo thinks 'name' is String
            ],
        ),
        'count': InferredType(
            type=Number,
            evidences=[
                FakeFtlSource('bar', 1, 9),  # We are calling foo
                FakeFtlSource('foo', 2, 35),  # foo thinks 'count' is Number
            ],
        ),
    }
Exemple #4
0
def test_string():
    assert ftl_to_types("""
        foo = Hello { $name }
    """) == {
        'foo': {
            'name': InferredType(type=String,
                                 evidences=[FakeFtlSource('foo', 1, 15)])
        }
    }
Exemple #5
0
def test_datetime_function():
    assert ftl_to_types("""
       foo = Today is { DATETIME($today) }!
    """) == {
        'foo': {
            'today': InferredType(
                type=DateTime,
                evidences=[FakeFtlSource('foo', 1, 18)]
            )
        }
    }
Exemple #6
0
def test_number_function():
    assert ftl_to_types("""
        foo = You have { NUMBER($count) } emails!
    """) == {
        'foo': {
            'count': InferredType(
                type=Number,
                evidences=[FakeFtlSource('foo', 1, 18)]
            )
        }
    }
Exemple #7
0
def test_conflict():
    assert ftl_to_types("""
        foo =
           Today is { DATETIME($count) }!
           You have { NUMBER($count) } emails!
    """) == {
        'foo': {
            'count': Conflict(
                types=[
                    InferredType(
                        type=DateTime,
                        evidences=[FakeFtlSource('foo', 2, 15)]
                    ),
                    InferredType(
                        type=Number,
                        evidences=[FakeFtlSource('foo', 3, 15)],
                    ),
                ],
                message_source=FakeFtlSource('foo', 1, 1)
            )
        }
    }
Exemple #8
0
def test_select_string():
    arg_types = ftl_to_types("""
        bar = { $arg ->
            *[Hello]   Hi
         }
    """)
    assert arg_types == {
        'bar': {
            'arg': InferredType(
                type=String,
                evidences=[
                    FakeFtlSource('bar', 2, 7),
                ]
            )
        }
    }
Exemple #9
0
def test_select_plural_form():
    arg_types = ftl_to_types("""
        bar = { $arg ->
            *[one] One
         }
    """)
    assert arg_types == {
        'bar': {
            'arg': InferredType(
                type=Number,
                evidences=[
                    FakeFtlSource('bar', 2, 7),
                ]
            )
        }
    }
Exemple #10
0
def test_select_mixed_numeric():
    arg_types = ftl_to_types("""
        bar = { $arg ->
             [0]   Zero
            *[one] One
         }
    """)
    assert arg_types == {
        'bar': {
            'arg': InferredType(
                type=Number,
                evidences=[
                    FakeFtlSource('bar', 2, 7),
                    FakeFtlSource('bar', 3, 7),
                ]
            )
        }
    }
Exemple #11
0
def test_select_string_with_plural_cat():
    # Plural category should not be treated as number if
    # other non plural category strings are present
    arg_types = ftl_to_types("""
        bar = { $arg ->
            *[zero]   Zero
             [positive]  Positive
             [negative]  Negative
         }
    """)
    assert arg_types == {
        'bar': {
            'arg': InferredType(
                type=String,
                evidences=[
                    FakeFtlSource('bar', 2, 7),
                    FakeFtlSource('bar', 3, 7),
                    FakeFtlSource('bar', 4, 7),
                ]
            )
        }
    }