' new_features_test.pb - Tests all newly implemented features (May 2026)
' Covers: INT, FIX, ROUND, MIN, MAX, HEX$, OCT$, BIN$, RND,
'         INCR, DECR, ITERATE, SWAP, REPLACE, CHR$ multi-arg,
'         SELECT CASE, DATE$, TIME$, ENVIRON$, COMMAND$,
'         INKEY$, WAITKEY$, INPUT, LINE INPUT, FORMAT$

FUNCTION PBMAIN() AS LONG
    LOCAL result AS LONG
    LOCAL s AS STRING
    LOCAL i AS LONG
    LOCAL d AS DOUBLE

    result = 0

    ' --- Phase B: Math Functions ---
    DIM int_val AS DOUBLE
    int_val = INT(3.7)
    int_val = INT(-3.7)

    DIM fix_val AS DOUBLE
    fix_val = FIX(3.7)
    fix_val = FIX(-3.7)

    DIM rnd_val AS DOUBLE
    rnd_val = ROUND(3.14159, 2)
    rnd_val = ROUND(3.7)

    DIM min_val AS DOUBLE
    min_val = MIN(10, 20)

    DIM max_val AS DOUBLE
    max_val = MAX(10, 20)

    ' --- Phase C: String Conversions ---
    DIM hex_str AS STRING
    hex_str = HEX$(255)
    hex_str = HEX$(15, 4)

    DIM oct_str AS STRING
    oct_str = OCT$(8)

    DIM bin_str AS STRING
    bin_str = BIN$(5)

    ' --- RND ---
    DIM rand_val AS DOUBLE
    rand_val = RND()
    rand_val = RND(-1)

    ' --- Phase D: Utility Statements ---
    DIM counter AS LONG
    counter = 0
    INCR counter
    INCR counter, 5

    DECR counter
    DECR counter, 2

    ' --- SWAP ---
    DIM a AS LONG
    DIM b AS LONG
    a = 10
    b = 20
    SWAP a, b

    ' --- Phase E: String Operations ---
    ' CHR$ multi-arg
    s = CHR$(13, 10)

    ' REPLACE
    DIM rstr AS STRING
    rstr = "Hello World"
    REPLACE "World" WITH "PBXB64" IN rstr

    ' --- Phase F: SELECT CASE ---
    DIM case_val AS LONG
    case_val = 2
    SELECT CASE case_val
        CASE 1, 2, 3
            result = 1
        CASE 4 TO 10
            result = 2
        CASE IS > 10
            result = 3
        CASE ELSE
            result = 0
    END SELECT

    ' SELECT CASE with string-like conditions
    DIM case_val2 AS LONG
    case_val2 = 15
    SELECT CASE case_val2
        CASE 0
            result = 0
        CASE 5 TO 10
            result = 5
        CASE IS > 20
            result = 20
        CASE ELSE
            result = 15
    END SELECT

    ' --- ITERATE ---
    DIM iter_sum AS LONG
    iter_sum = 0
    FOR i = 1 TO 10
        IF i = 5 THEN
            ITERATE FOR
        END IF
        iter_sum = iter_sum + i
    NEXT i

    ' --- Phase G: Date/Time & Environment ---
    s = DATE$
    s = TIME$
    s = ENVIRON$("PATH")
    s = COMMAND$

    ' --- Phase H: Console I/O ---
    s = INKEY$
    s = WAITKEY$

    ' --- FORMAT$ ---
    s = FORMAT$(1234.5, "")

    ' --- Final test of ITERATE ---
    DIM iter_test AS LONG
    iter_test = iter_sum

    FUNCTION = result
END FUNCTION
