| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | #!/usr/bin/env zsh
 | 
					
						
							|  |  |  | # ------------------------------------------------------------------------------------------------- | 
					
						
							|  |  |  | # Copyright (c) 2016 zsh-syntax-highlighting contributors | 
					
						
							|  |  |  | # All rights reserved. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Redistribution and use in source and binary forms, with or without modification, are permitted | 
					
						
							|  |  |  | # provided that the following conditions are met: | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  * Redistributions of source code must retain the above copyright notice, this list of conditions | 
					
						
							|  |  |  | #    and the following disclaimer. | 
					
						
							|  |  |  | #  * Redistributions in binary form must reproduce the above copyright notice, this list of | 
					
						
							|  |  |  | #    conditions and the following disclaimer in the documentation and/or other materials provided | 
					
						
							|  |  |  | #    with the distribution. | 
					
						
							|  |  |  | #  * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors | 
					
						
							|  |  |  | #    may be used to endorse or promote products derived from this software without specific prior | 
					
						
							|  |  |  | #    written permission. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | 
					
						
							|  |  |  | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 
					
						
							|  |  |  | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | 
					
						
							|  |  |  | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
					
						
							|  |  |  | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | 
					
						
							|  |  |  | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 
					
						
							|  |  |  | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  | # ------------------------------------------------------------------------------------------------- | 
					
						
							|  |  |  | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- | 
					
						
							|  |  |  | # vim: ft=zsh sw=2 ts=2 et | 
					
						
							|  |  |  | # ------------------------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | emulate -LR zsh | 
					
						
							| 
									
										
										
										
											2016-09-25 08:01:54 +00:00
										 |  |  | setopt localoptions extendedglob | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Argument parsing. | 
					
						
							| 
									
										
										
										
											2016-07-29 19:02:40 +00:00
										 |  |  | if (( $# != 3 )) || [[ $1 == -* ]]; then | 
					
						
							|  |  |  |   print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  |   print -r -- >&2 "" | 
					
						
							| 
									
										
										
										
											2016-08-11 19:37:37 +00:00
										 |  |  |   print -r -- >&2 "Generate highlighters/HIGHLIGHTER/test-data/BASENAME.zsh based on the" | 
					
						
							| 
									
										
										
										
											2016-07-29 19:02:40 +00:00
										 |  |  |   print -r -- >&2 "current highlighting of BUFFER." | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | buffer=$1 | 
					
						
							| 
									
										
										
										
											2016-07-29 19:02:40 +00:00
										 |  |  | ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) | 
					
						
							| 
									
										
										
										
											2016-09-24 17:06:21 +00:00
										 |  |  | fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Load the main script. | 
					
						
							|  |  |  | . ${0:A:h:h}/zsh-syntax-highlighting.zsh | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style | 
					
						
							|  |  |  | _zsh_highlight_add_highlight() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   region_highlight+=("$1 $2 $3") | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 17:07:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | # Copyright block | 
					
						
							| 
									
										
										
										
											2016-09-24 17:07:01 +00:00
										 |  |  | year="`LC_ALL=C date +%Y`" | 
					
						
							|  |  |  | if ! read -q "?Set copyright year to $year? "; then | 
					
						
							|  |  |  |   year="YYYY" | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | exec >$fname | 
					
						
							|  |  |  | <$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" | 
					
						
							|  |  |  | # Assumes stdout is line-buffered | 
					
						
							|  |  |  | git add -- $fname | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Buffer | 
					
						
							|  |  |  | print -n 'BUFFER=' | 
					
						
							| 
									
										
										
										
											2016-09-25 08:01:54 +00:00
										 |  |  | if [[ $buffer != (#s)[$'\t -~']#(#e) ]]; then | 
					
						
							|  |  |  |   print -r -- ${(qqqq)buffer} | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   print -r -- ${(qq)buffer} | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  | echo "" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Expectations | 
					
						
							|  |  |  | print 'expected_region_highlight=(' | 
					
						
							|  |  |  | () { | 
					
						
							|  |  |  |   local i | 
					
						
							|  |  |  |   local PREBUFFER | 
					
						
							|  |  |  |   local BUFFER | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   PREBUFFER="" | 
					
						
							|  |  |  |   BUFFER="$buffer" | 
					
						
							|  |  |  |   region_highlight=() | 
					
						
							| 
									
										
										
										
											2016-09-25 11:38:43 +00:00
										 |  |  |   # TODO: use run_test() from tests/test-highlighting.zsh (to get a tempdir) | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  |   _zsh_highlight | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for ((i=1; i<=${#region_highlight}; i++)); do | 
					
						
							|  |  |  |     local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) | 
					
						
							|  |  |  |     integer start=$highlight_zone[1] end=$highlight_zone[2] | 
					
						
							|  |  |  |     if (( start < end )) # region_highlight ranges are half-open | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       (( --end )) # convert to closed range, like expected_region_highlight | 
					
						
							|  |  |  |       (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-09-25 08:01:54 +00:00
										 |  |  |     printf "  %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} ${${(qqqq)BUFFER[start,end]}[3,-2]} | 
					
						
							| 
									
										
										
										
											2016-07-28 23:15:32 +00:00
										 |  |  |   done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | print ')' |