#!/bin/sh # # Copyright (c) 2008 Timo Hirvonen # global test_description := ''Test diff/status color escape codes'' source ./test-lib.sh proc color { global actual := $[git config --get-color no.such.slot $1] && test $actual = "$2" } proc invalid_color { test_must_fail git config --get-color no.such.slot $1 } test_expect_success 'reset' ' color "reset" "[m" ' test_expect_success 'attribute before color name' ' color "bold red" "[1;31m" ' test_expect_success 'color name before attribute' ' color "red bold" "[1;31m" ' test_expect_success 'attr fg bg' ' color "ul blue red" "[4;34;41m" ' test_expect_success 'fg attr bg' ' color "blue ul red" "[4;34;41m" ' test_expect_success 'fg bg attr' ' color "blue red ul" "[4;34;41m" ' test_expect_success 'fg bg attr...' ' color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" ' # note that nobold and nodim are the same code (22) test_expect_success 'attr negation' ' color "nobold nodim noul noblink noreverse" "[22;24;25;27m" ' test_expect_success '"no-" variant of negation' ' color "no-bold no-blink" "[22;25m" ' test_expect_success 'long color specification' ' color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m" ' test_expect_success 'absurdly long color specification' ' color \ "#ffffff #ffffff bold nobold dim nodim italic noitalic ul noul blink noblink reverse noreverse strike nostrike" \ "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m" ' test_expect_success '0-7 are aliases for basic ANSI color names' ' color "0 7" "[30;47m" ' test_expect_success '256 colors' ' color "254 bold 255" "[1;38;5;254;48;5;255m" ' test_expect_success '24-bit colors' ' color "#ff00ff black" "[38;2;255;0;255;40m" ' test_expect_success '"normal" yields no color at all"' ' color "normal black" "[40m" ' test_expect_success '-1 is a synonym for "normal"' ' color "-1 black" "[40m" ' test_expect_success 'color too small' ' invalid_color "-2" ' test_expect_success 'color too big' ' invalid_color "256" ' test_expect_success 'extra character after color number' ' invalid_color "3X" ' test_expect_success 'extra character after color name' ' invalid_color "redX" ' test_expect_success 'extra character after attribute' ' invalid_color "dimX" ' test_expect_success 'unknown color slots are ignored (diff)' ' git config color.diff.nosuchslotwilleverbedefined white && git diff --color ' test_expect_success 'unknown color slots are ignored (branch)' ' git config color.branch.nosuchslotwilleverbedefined white && git branch -a ' test_expect_success 'unknown color slots are ignored (status)' ' git config color.status.nosuchslotwilleverbedefined white && { git status; ret=$?; } && case $ret in 0|1) : ok ;; *) false ;; esac ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test diff/status color escape codes">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: color body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:actual) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(config)} {(--get-color)} {(no.such.slot)} {(DQ ($ VSub_Number "$1"))} ) ] ) left_token: spids: [31 43] ) } spids: [30] ) ] spids: [30] ) (C {(test)} {(DQ ($ VSub_Name "$actual"))} {(Lit_Other "=")} {(DQ ("\u001b") ($ VSub_Number "$2"))} ) ] op_id: Op_DAmp ) ] spids: [27] ) spids: [23 26] ) (FuncDef name: invalid_color body: (BraceGroup children: [ (C {(test_must_fail)} {(git)} {(config)} {(--get-color)} {(no.such.slot)} {(DQ ($ VSub_Number "$1"))} ) ] spids: [68] ) spids: [64 67] ) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\tcolor \"reset\" \"[m\"\n">)}) (C {(test_expect_success)} {(SQ <"attribute before color name">)} {(SQ <"\n"> <"\tcolor \"bold red\" \"[1;31m\"\n">)} ) (C {(test_expect_success)} {(SQ <"color name before attribute">)} {(SQ <"\n"> <"\tcolor \"red bold\" \"[1;31m\"\n">)} ) (C {(test_expect_success)} {(SQ <"attr fg bg">)} {(SQ <"\n"> <"\tcolor \"ul blue red\" \"[4;34;41m\"\n">)} ) (C {(test_expect_success)} {(SQ <"fg attr bg">)} {(SQ <"\n"> <"\tcolor \"blue ul red\" \"[4;34;41m\"\n">)} ) (C {(test_expect_success)} {(SQ <"fg bg attr">)} {(SQ <"\n"> <"\tcolor \"blue red ul\" \"[4;34;41m\"\n">)} ) (C {(test_expect_success)} {(SQ <"fg bg attr...">)} {(SQ <"\n"> <"\tcolor \"blue bold dim ul blink reverse\" \"[1;2;4;5;7;34m\"\n">)} ) (C {(test_expect_success)} {(SQ <"attr negation">)} {(SQ <"\n"> <"\tcolor \"nobold nodim noul noblink noreverse\" \"[22;24;25;27m\"\n">)} ) (C {(test_expect_success)} {(SQ <"\"no-\" variant of negation">)} {(SQ <"\n"> <"\tcolor \"no-bold no-blink\" \"[22;25m\"\n">)} ) (C {(test_expect_success)} {(SQ <"long color specification">)} { (SQ <"\n"> <"\tcolor \"254 255 bold dim ul blink reverse\" \"[1;2;4;5;7;38;5;254;48;5;255m\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"absurdly long color specification">)} { (SQ <"\n"> <"\tcolor \\\n"> <"\t \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n"> <"\t ul noul blink noblink reverse noreverse strike nostrike\" \\\n"> <"\t \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"0-7 are aliases for basic ANSI color names">)} {(SQ <"\n"> <"\tcolor \"0 7\" \"[30;47m\"\n">)} ) (C {(test_expect_success)} {(SQ <"256 colors">)} {(SQ <"\n"> <"\tcolor \"254 bold 255\" \"[1;38;5;254;48;5;255m\"\n">)} ) (C {(test_expect_success)} {(SQ <"24-bit colors">)} {(SQ <"\n"> <"\tcolor \"#ff00ff black\" \"[38;2;255;0;255;40m\"\n">)} ) (C {(test_expect_success)} {(SQ <"\"normal\" yields no color at all\"">)} {(SQ <"\n"> <"\tcolor \"normal black\" \"[40m\"\n">)} ) (C {(test_expect_success)} {(SQ <"-1 is a synonym for \"normal\"">)} {(SQ <"\n"> <"\tcolor \"-1 black\" \"[40m\"\n">)} ) (C {(test_expect_success)} {(SQ <"color too small">)} {(SQ <"\n"> <"\tinvalid_color \"-2\"\n">)}) (C {(test_expect_success)} {(SQ <"color too big">)} {(SQ <"\n"> <"\tinvalid_color \"256\"\n">)}) (C {(test_expect_success)} {(SQ <"extra character after color number">)} {(SQ <"\n"> <"\tinvalid_color \"3X\"\n">)} ) (C {(test_expect_success)} {(SQ <"extra character after color name">)} {(SQ <"\n"> <"\tinvalid_color \"redX\"\n">)} ) (C {(test_expect_success)} {(SQ <"extra character after attribute">)} {(SQ <"\n"> <"\tinvalid_color \"dimX\"\n">)} ) (C {(test_expect_success)} {(SQ <"unknown color slots are ignored (diff)">)} { (SQ <"\n"> <"\tgit config color.diff.nosuchslotwilleverbedefined white &&\n"> <"\tgit diff --color\n"> ) } ) (C {(test_expect_success)} {(SQ <"unknown color slots are ignored (branch)">)} { (SQ <"\n"> <"\tgit config color.branch.nosuchslotwilleverbedefined white &&\n"> <"\tgit branch -a\n"> ) } ) (C {(test_expect_success)} {(SQ <"unknown color slots are ignored (status)">)} { (SQ <"\n"> <"\tgit config color.status.nosuchslotwilleverbedefined white &&\n"> <"\t{ git status; ret=$?; } &&\n"> <"\tcase $ret in 0|1) : ok ;; *) false ;; esac\n"> ) } ) (C {(test_done)}) ] )