"""Unit tests for the location operation-code derivation.

Locations carry no dedicated code column, so the operation code is the leading
whitespace-delimited token of the location name (e.g. '0615 Blisk Inspection'
-> '0615'). Printed asset labels for measuring tools encode this so every tool
at one operation shares one code.
"""

from shopdb.core.models.location import derive_locationcode


def test_derive_leading_numeric_token():
    assert derive_locationcode('0615 Blisk Inspection') == '0615'


def test_derive_single_token_name():
    assert derive_locationcode('Lab') == 'Lab'


def test_derive_strips_surrounding_whitespace():
    assert derive_locationcode('  0700  Final  ') == '0700'


def test_derive_none_when_blank():
    assert derive_locationcode('') is None
    assert derive_locationcode('   ') is None
    assert derive_locationcode(None) is None
