File size: 1,613 Bytes
b727f11
 
 
 
 
5423dad
b727f11
52a9362
b727f11
5423dad
 
 
 
b2b5f1c
 
 
 
 
 
 
52a9362
b2b5f1c
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pathlib import Path

from demo import examples


def test_examples_prepare_from_core_checkout(tmp_path):
    rows = examples.prepare_examples(tmp_path)
    assert len(rows) == len(examples.EXAMPLE_NAMES) == 63
    assert len(examples.GHIDRA_EXAMPLE_NAMES) == 21
    assert all(Path(row[0]).is_file() for row in rows)
    assert all(Path(row[0]).is_relative_to(tmp_path) for row in rows)
    assert all(row[2] for row in rows)
    assert len(examples.reference_sources()) == len(rows)


def test_example_groups_cover_catalog_once():
    members = [name for _, names in examples.EXAMPLE_GROUPS for name in names]
    assert len(members) == len(set(members)) == len(examples.EXAMPLE_NAMES)
    assert set(members) == set(examples.EXAMPLE_NAMES)
    groups = examples.example_groups(examples.EXAMPLE_NAMES)
    assert [len(indices) for _, indices in groups] == [6, 7, 8, 3, 18, 21]
    for _, indices in groups:
        assert list(indices) == sorted(indices)


def test_example_groups_filter_subsets_and_omit_empty_sections():
    names = ("ghidra-identical", "tail-call", "identical")
    assert examples.example_groups(names) == (
        ("Basics", (2,)), ("Calls and memory", (1,)), ("Ghidra exports", (0,)))
    assert examples.example_groups(()) == ()
    assert examples.example_groups(examples.GHIDRA_EXAMPLE_NAMES) == (
        ("Ghidra exports", tuple(range(21))),)
    original = examples.example_groups(examples.ORIGINAL_EXAMPLE_NAMES)
    assert all(label != "Ghidra exports" for label, _ in original)
    assert sum(len(indices) for _, indices in original) == len(examples.ORIGINAL_EXAMPLE_NAMES)