XQuery compare order of two sequences
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):

declare function local:testOrder2($baseSequence, $testSequence) {
    let $positions := $testSequence ! index-of($baseSequence, .)
    return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};


Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!