diff --git a/.gitignore b/.gitignore index 71a0ace..8f9e9b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,19 @@ pkg -doc lib/i[3-9]86* lib/x86* *.swp tags +.DS_Store +src/hash/*_hash.h +src/hash/language_hash.c +src/parsers/*.h +src/parser.o +test/unit/run_tests +bin/ +ruby/ohcount.so +ruby/ohcount_wrap.c +test/unit/run_tests.dSYM/ +build-python/ +python/ohcount.py +.rvmrc +.ruby-version diff --git a/PARSER_DOC b/PARSER_DOC deleted file mode 100644 index 510513c..0000000 --- a/PARSER_DOC +++ /dev/null @@ -1,311 +0,0 @@ -PARSER_DOC written by Mitchell Foral - -Overview: - I will assume the reader has a decent knowledge of how Ragel works and the - Ragel syntax. If not, please review the Ragel manual found at: - http://research.cs.queensu.ca/~thurston/ragel/ - - All parsers must at least: - * Call a callback function when a line of code is parsed. - * Call a callback function when a line of comment is parsed. - * Call a callback function when a blank line is parsed. - Additionally a parser can call the callback function for each position of - entities parsed. - - Take a look at c.rl and even keep it open for reference when reading this - document to better understand how parsers work and how to write one. - -Writing a Parser: - First create your parser in ext/ohcount_native/ragel_parsers/. Its name - should be the language you are parsing with a '.rl' extension. You will not - have to manually compile any parsers, as the Rakefile does this automatically - for you. Every parser must have the following at the top: - -/************************* Required for every parser *************************/ -#ifndef RAGEL_C_PARSER -#define RAGEL_C_PARSER - -#include "ragel_parser_macros.h" - -// the name of the language -const char *C_LANG = "c"; - -// the languages entities -const char *c_entities[] = { - "space", "comment", "string", "number", "preproc", - "keyword", "identifier", "operator", "any" -}; - -// constants associated with the entities -enum { - C_SPACE = 0, C_COMMENT, C_STRING, C_NUMBER, C_PREPROC, - C_KEYWORD, C_IDENTIFIER, C_OPERATOR, C_ANY -}; - -/*****************************************************************************/ - - And the following at the bottom: - -/************************* Required for every parser *************************/ - -/* Parses a string buffer with C/C++ code. - * - * @param *buffer The string to parse. - * @param length The length of the string to parse. - * @param count Integer flag specifying whether or not to count lines. If yes, - * uses the Ragel machine optimized for counting. Otherwise uses the Ragel - * machine optimized for returning entity positions. - * @param *callback Callback function. If count is set, callback is called for - * every line of code, comment, or blank with 'lcode', 'lcomment', and - * 'lblank' respectively. Otherwise callback is called for each entity found. - */ -void parse_c(char *buffer, int length, int count, - void (*callback) (const char *lang, const char *entity, int start, int end) - ) { - init - - %% write init; - cs = (count) ? c_en_c_line : c_en_c_entity; - %% write exec; - - // if no newline at EOF; callback contents of last line - if (count) { process_last_line(C_LANG) } -} - -#endif - -/*****************************************************************************/ - - (Your parser will go between these two blocks.) - - The code can be found in the existing c.rl parser. You will need to change: - * RAGEL_[lang]_PARSER - Replace [lang] with your language name. So if you - are writing a C parser, it would be RAGEL_C_PARSER. - * [lang]_LANG - Set the variable name to be [lang]_LANG and its value to be - the name of your language to parse. [lang] is your language name. For C it - would be C_LANG. - * [lang]_entities - Set the variable name to be [lang]_entities (e.g. - c_entries) The value is an array of string entities your language has. - For example C has comment, string, number, etc. entities. You should - definately have "space", and "any" entities. "any" entities are typically - used for entity machines (discussed later) and match any character that - is not recognized so the parser does not do something unpredictable. - * enum - Change the value of the enum to correspond with your entities. So - if in your parser you look up [lang]_entities[ENTITY], you will get the - associated entity's string name. - * parse_[lang] - Set the function name to parse_[lang] where again, [lang] - is the name of your language. In the case of C, it is parse_c. - * [lang]_en_[lang]_line - The line counting machine. - * [lang]_en_[lang]_entity - The entity machine. - - You may be asking why you have to rename variables and functions. Well if - variables have the same name in header files (which is what parsers are), - the compiler complains. Also, when you have languages embedded inside each - other, any identifiers with the same name can easily be mixed up. It is also - important to prefix your Ragel definitions with your language to avoid - conflicts with other parsers. - - Additional variables available to parsers are in the "ragel_parser_macros.h" - file. Take a look at it and try to understand what the variables are used for. - They will make more sense later on. - - Now you can define your Ragel parser. Name your machine after your language, - 'write data', and include 'common.rl', a file with common Ragel definitions, - actions, etc. For example: - %%{ - machine c; - write data; - include "common.rl"; - - ... - }%% - - Before you begin to write patterns for each entity in your language, you need - to understand how the parser should work. - - Each parser has two machines: one optimized for counting lines of code, - comments, and blanks; the other for identifying entity positions in the - buffer. - - Line Counting Machine: - This machine should be written as a line-by-line parser for multiple lines. - This means you match any combination of entities except a newline up until - you do reach a newline. If the line contains only spaces, or nothing at all, - it is blank. If the line contains spaces at first, but then a comment, or - just simply a comment, the line is a comment. If the line contains anything - but a comment after spaces (if there are any), it is a line of code. You - will do this using a Ragel scanner. - The callback function will be called for each line parsed. - - Scanner Parser Structure: - A scanner parser will look like this: - [lang]_line := |* - entity1 ${ entity = ENTITY1; } => [lang]_ccallback; - entity2 ${ entity = ENTITY2; } => [lang]_ccallback; - ... - entityn ${ entity = ENTITYN; } => [lang]_ccallback; - *|; - (As usual, replace [lang] with your language name.) - Each entity is the pattern for an entity to match, the last one typically - being the newline entity. For each match, the variable is set to a - constant defined in the enum, and the main action is called (you will need - to create this action above the scanner). - - When you detect whether or not a line is code or comment, you should call - the appropriate 'code' or 'comment' action defined in common.rl as soon - as possible. It is not necessary to worry about whether or not these - actions are called more than once for a given line; the first call to - either sets the status of the line permanently. Sometimes you cannot call - 'code' or 'comment' for one reason or another. Do not worry, as this is - discussed later. - - When you reach a newline, you will need to decide whether the current line - is a line of code, comment, or blank. This is easy. Simply check if the - line_contains_code or whole_line_comment variables are set to 1. If - neither of them are, the line is blank. Then call the callback function - (not action) with an "lcode", "lcomment", or "lblank" string, and the - start and end positions of that line (including the newline). The start - position of the line is in the line_start variable. It should be set at - the beginning of every line either through the 'code' or 'comment' - actions, or manually in the main action. Finally the line_contains_code, - whole_line_comment, and line_start state variables must be reset. All this - should be done within the main action shown below. - Note: For most parsers, the std_newline(lang) macro is sufficient and does - everything in the main action mentioned above. The lang parameter is the - [lang]_LANG string. - - Main Action Structure: - The main action looks like this: - action [lang]_ccallback { - switch(entity) { - when ENTITY1: - ... - break; - when ENTITY2: - ... - break; - ... - when ENTITYN: - ... - break; - } - } - - Defining Patterns for Entities: - Now it is time to write patterns for each entity in your language. That - does not seem very hard, except when your entity can cover multiple lines. - Comments and strings in particular can do this. To make an accurate line - counter, you will need to count the lines covered by multi-line entities. - When you detect a newline inside your multi-line entity, you should set - the entity variable to be INTERNAL_NL (-2) and call the main action. The - main action should have a case for INTERNAL_NL separate from the newline - entity. In it, you will check if the current line is code or comment and - call the callback function with the appropriate string ("lcode" or - "lcomment") and beginning and end of the line (including the newline). - Afterwards, you will reset the line_contains_code and whole_line_comment - state variables. Then set the line_start variable to be p, the current - Ragel buffer position. Because line_contains_code and whole_line_comment - have been reset, any non-newline and non-space character in the multi-line - pattern should set line_contains_code or whole_line_comment back to 1. - Otherwise you would count the line as blank. - Note: For most parsers, the std_internal_newline(lang) macro is sufficient - and does everything in the main action mentioned above. The lang parameter - is the [lang]_LANG string. - - For multi-line matches, it is important to call the 'code' or 'comment' - actions (mentioned earlier) before an internal newline is detected so the - line_contains_code and whole_line_comment variables are properly set. For - other entities, you can use the 'code' macro inside the main action which - executes the same code as the Ragel 'code' action. Other C macros are - 'comment' and 'ls', the latter is typically used for the SPACE entity when - defining line_start. - - Also for multi-line matches, it may be necessary to use the 'enqueue' and - 'commit' actions. If it is possible that a multi-line entity will not have - an ending delimiter (for example a string), use the 'enqueue' action as - soon as the start delimitter has been detected, and the 'commit' action as - soon as the end delimitter has been detected. This will eliminate the - potential for any counting errors. - - Notes: - * You can be a bit sloppy with the line counting machine. For example the - only C entities that can contain newlines are strings and comments, so - INTERNAL_NL would only be necessary inside them. Other than those, - anything other than spaces is considered code, so do not waste your time - defining specific patterns for other entities. - - Parsers with Embedded Languages: - Notation: [lang] is the parent language, [elang] is the embedded language. - - To write a parser with embedded languages (such as HTML with embedded CSS - and Javascript), you should first #include the parser(s) above your Ragel - code. The header file is "[elang]_parser.h". - - Next, after the inclusion of 'common.rl', add '#EMBED([elang])' on - separate lines for each embedded language. The Rakefile looks for these - special comments to embed the language for you automatically. - - In your main action, you need to add another entity CHECK_BLANK_ENTRY. It - should call the 'check_blank_entry([lang]_LANG)' macro. Blank entries are - an entry into an embedded language, but the rest of the line is blank - before a newline. For example, a CSS entry in HTML is something like: - +html code +html code new +html code diff --git a/test/expected_dir/diff1_old.html b/test/expected_dir/diff1_old.html new file mode 100644 index 0000000..8e6d912 --- /dev/null +++ b/test/expected_dir/diff1_old.html @@ -0,0 +1,11 @@ +html code +html code +html code +html code +html code +html code old +html code diff --git a/test/expected_dir/diff2_new.c b/test/expected_dir/diff2_new.c new file mode 100644 index 0000000..7ba80e9 --- /dev/null +++ b/test/expected_dir/diff2_new.c @@ -0,0 +1,7 @@ +c comment /* new */ +c code #include 'foo.c' +c comment /* common */ +c code int do_stuff(old_code) { +c code int common; +c code int new_var; +c code } diff --git a/test/expected_dir/diff2_old.c b/test/expected_dir/diff2_old.c new file mode 100644 index 0000000..906e6f0 --- /dev/null +++ b/test/expected_dir/diff2_old.c @@ -0,0 +1,7 @@ +c comment /* old */ +c code #include 'foo.c' +c comment /* common */ +c code int do_stuff(old_code) { +c code int common; +c code int old_var; +c code } diff --git a/test/expected_dir/diff3_new.xml b/test/expected_dir/diff3_new.xml new file mode 100644 index 0000000..b01c982 --- /dev/null +++ b/test/expected_dir/diff3_new.xml @@ -0,0 +1,3 @@ +xml code +xml code new +xml code diff --git a/test/expected_dir/diff3_old.xml b/test/expected_dir/diff3_old.xml new file mode 100644 index 0000000..145f963 --- /dev/null +++ b/test/expected_dir/diff3_old.xml @@ -0,0 +1,3 @@ +xml code +xml code old +xml code diff --git a/test/expected_dir/dylan1.dylan b/test/expected_dir/dylan1.dylan new file mode 100644 index 0000000..4fcf478 --- /dev/null +++ b/test/expected_dir/dylan1.dylan @@ -0,0 +1,17 @@ +dylan comment // random program i found +dylan code define function describe-list(my-list :: , #key verbose?) => () +dylan code format(*standard-output*, "{a , size: %d", my-list.size); +dylan code if (verbose?) +dylan code format(*standard-output*, ", elements:"); +dylan code for (item in my-list) +dylan code format(*standard-output*, " %=", item); +dylan code end for; +dylan code end if; +dylan code format(*standard-output*, "}"); +dylan code end function; +dylan blank +dylan code describe-list(#(1, 2, 3, 4, 5, 6)); +dylan comment // prints "{a , size: 6}" +dylan blank +dylan code describe-list(#(5, 7, 3), verbose?: #t); +dylan comment // prints "{a , size: 3, elements: 5 7 3}" diff --git a/test/expected_dir/dylan1.dylan/dylan/blanks b/test/expected_dir/dylan1.dylan/dylan/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/dylan1.dylan/dylan/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/dylan1.dylan/dylan/code b/test/expected_dir/dylan1.dylan/dylan/code deleted file mode 100644 index cbeac86..0000000 --- a/test/expected_dir/dylan1.dylan/dylan/code +++ /dev/null @@ -1,12 +0,0 @@ -define function describe-list(my-list :: , #key verbose?) => () -format(*standard-output*, "{a , size: %d", my-list.size); -if (verbose?) -format(*standard-output*, ", elements:"); -for (item in my-list) -format(*standard-output*, " %=", item); -end for; -end if; -format(*standard-output*, "}"); -end function; -describe-list(#(1, 2, 3, 4, 5, 6)); -describe-list(#(5, 7, 3), verbose?: #t); diff --git a/test/expected_dir/dylan1.dylan/dylan/comment b/test/expected_dir/dylan1.dylan/dylan/comment deleted file mode 100644 index 6687ac5..0000000 --- a/test/expected_dir/dylan1.dylan/dylan/comment +++ /dev/null @@ -1,3 +0,0 @@ -// random program i found -// prints "{a , size: 6}" -// prints "{a , size: 3, elements: 5 7 3}" diff --git a/test/expected_dir/eiffel.e b/test/expected_dir/eiffel.e new file mode 100644 index 0000000..e90c775 --- /dev/null +++ b/test/expected_dir/eiffel.e @@ -0,0 +1,13 @@ +eiffel code class +eiffel code HELLO_WORLD +eiffel code create +eiffel code make +eiffel code feature +eiffel code make +eiffel code do +eiffel comment -- prints "Hello world!" and starts new line +eiffel blank +eiffel code print ("Hello, world!%N") +eiffel blank +eiffel code end +eiffel code end diff --git a/test/expected_dir/eiffel.e/eiffel/blanks b/test/expected_dir/eiffel.e/eiffel/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/eiffel.e/eiffel/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/eiffel.e/eiffel/code b/test/expected_dir/eiffel.e/eiffel/code deleted file mode 100644 index 5c4b96c..0000000 --- a/test/expected_dir/eiffel.e/eiffel/code +++ /dev/null @@ -1,10 +0,0 @@ -class -HELLO_WORLD -create -make -feature -make -do -print ("Hello, world!%N") -end -end diff --git a/test/expected_dir/eiffel.e/eiffel/comment b/test/expected_dir/eiffel.e/eiffel/comment deleted file mode 100644 index 734b783..0000000 --- a/test/expected_dir/eiffel.e/eiffel/comment +++ /dev/null @@ -1 +0,0 @@ --- prints "Hello world!" and starts new line diff --git a/test/expected_dir/el1.el b/test/expected_dir/el1.el new file mode 100644 index 0000000..ba7de4c --- /dev/null +++ b/test/expected_dir/el1.el @@ -0,0 +1,22 @@ +emacslisp code (if (string-equal "21" (substring (emacs-version) 10 12)) +emacslisp code (progn +emacslisp code (blink-cursor-mode 0) +emacslisp comment ;; Insert newline when you press `C-n' (next-line) +emacslisp comment ;; at the end of the buffer +emacslisp blank +emacslisp code (setq next-line-add-newlines t) +emacslisp comment ;; Turn on image viewing +emacslisp code (auto-image-file-mode t) +emacslisp comment ;; Turn on menu bar (this bar has text) +emacslisp comment ;; (Use numeric argument to turn on) +emacslisp code (menu-bar-mode 1) +emacslisp comment ;; Turn off tool bar (this bar has icons) +emacslisp comment ;; (Use numeric argument to turn on) +emacslisp code (tool-bar-mode nil) +emacslisp comment ;; Turn off tooltip mode for tool bar +emacslisp comment ;; (This mode causes icon explanations to pop up) +emacslisp comment ;; (Use numeric argument to turn on) +emacslisp code (tooltip-mode nil) +emacslisp comment ;; If tooltips turned on, make tips appear promptly +emacslisp code (setq tooltip-delay 0.1) ; default is one second +emacslisp code )) diff --git a/test/expected_dir/el1.el/emacslisp/blanks b/test/expected_dir/el1.el/emacslisp/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/el1.el/emacslisp/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/el1.el/emacslisp/code b/test/expected_dir/el1.el/emacslisp/code deleted file mode 100644 index 967f65b..0000000 --- a/test/expected_dir/el1.el/emacslisp/code +++ /dev/null @@ -1,10 +0,0 @@ -(if (string-equal "21" (substring (emacs-version) 10 12)) -(progn -(blink-cursor-mode 0) -(setq next-line-add-newlines t) -(auto-image-file-mode t) -(menu-bar-mode 1) -(tool-bar-mode nil) -(tooltip-mode nil) -(setq tooltip-delay 0.1) ; default is one second -)) diff --git a/test/expected_dir/el1.el/emacslisp/comment b/test/expected_dir/el1.el/emacslisp/comment deleted file mode 100644 index 59bffd7..0000000 --- a/test/expected_dir/el1.el/emacslisp/comment +++ /dev/null @@ -1,11 +0,0 @@ -;; Insert newline when you press `C-n' (next-line) -;; at the end of the buffer -;; Turn on image viewing -;; Turn on menu bar (this bar has text) -;; (Use numeric argument to turn on) -;; Turn off tool bar (this bar has icons) -;; (Use numeric argument to turn on) -;; Turn off tooltip mode for tool bar -;; (This mode causes icon explanations to pop up) -;; (Use numeric argument to turn on) -;; If tooltips turned on, make tips appear promptly diff --git a/test/expected_dir/english.st b/test/expected_dir/english.st new file mode 100644 index 0000000..e69de29 diff --git a/test/expected_dir/erl1.erl b/test/expected_dir/erl1.erl new file mode 100644 index 0000000..43da9d3 --- /dev/null +++ b/test/expected_dir/erl1.erl @@ -0,0 +1,189 @@ +erlang comment %%%---------------------------------------------------------------------- +erlang comment %%% File : erl1.erl +erlang comment %%% Author : Jason Allen - kinda - just repurposing random code +erlang comment %%% Purpose : Test out the erlang parsing +erlang comment %%% Created : 1/17/2007 by Jason Allen +erlang comment %%% Id : $Id: erl1.erl 1 2007-17-01 jason $ +erlang comment %%%---------------------------------------------------------------------- +erlang blank +erlang code -module(erl1). +erlang code -author('jason@ohloh.net'). +erlang code -vsn('$Revision: 1 $ '). +erlang blank +erlang comment %% External exports +erlang code -export([import_file/1, +erlang code import_dir/1]). +erlang blank +erlang code -include("random.hrl"). +erlang code -include("more_random.hrl"). +erlang blank +erlang comment %%%---------------------------------------------------------------------- +erlang comment %%% API +erlang comment %%%---------------------------------------------------------------------- +erlang blank +erlang code import_file(File) -> +erlang code User = filename:rootname(filename:basename(File)), +erlang code Server = filename:basename(filename:dirname(File)), +erlang code case (jlib:nodeprep(User) /= error) andalso +erlang code (jlib:nameprep(Server) /= error) of +erlang code true -> +erlang code case file:read_file(File) of +erlang code {ok, Text} -> +erlang code case xml_stream:parse_element(Text) of +erlang code El when element(1, El) == xmlelement -> +erlang code case catch process_xdb(User, Server, El) of +erlang code {'EXIT', Reason} -> +erlang code ?ERROR_MSG( +erlang code "Error while processing file \"~s\": ~p~n", +erlang code [File, Reason]), +erlang code {error, Reason}; +erlang code _ -> +erlang code ok +erlang code end; +erlang code {error, Reason} -> +erlang code ?ERROR_MSG("Can't parse file \"~s\": ~p~n", +erlang code [File, Reason]), +erlang code {error, Reason} +erlang code end; +erlang code {error, Reason} -> +erlang code ?ERROR_MSG("Can't read file \"~s\": ~p~n", [File, Reason]), +erlang code {error, Reason} +erlang code end; +erlang code false -> +erlang code ?ERROR_MSG("Illegal user/server name in file \"~s\"~n", [File]), +erlang code {error, "illegal user/server"} +erlang code end. +erlang blank +erlang blank +erlang code import_dir(Dir) -> +erlang code {ok, Files} = file:list_dir(Dir), +erlang code MsgFiles = lists:filter( +erlang code fun(FN) -> +erlang code case string:len(FN) > 4 of +erlang code true -> +erlang code string:substr(FN, +erlang code string:len(FN) - 3) == ".xml"; +erlang code _ -> +erlang code false +erlang code end +erlang code end, Files), +erlang code lists:foldl( +erlang code fun(FN, A) -> +erlang code Res = import_file(filename:join([Dir, FN])), +erlang code case {A, Res} of +erlang code {ok, ok} -> ok; +erlang code {ok, _} -> {error, "see aoabberd log for details"}; +erlang code _ -> A +erlang code end +erlang code end, ok, MsgFiles). +erlang blank +erlang comment %%%---------------------------------------------------------------------- +erlang comment %%% Internal functions +erlang comment %%%---------------------------------------------------------------------- +erlang blank +erlang code process_xdb(User, Server, {xmlelement, Name, _Attrs, Els}) -> +erlang code case Name of +erlang code "xdb" -> +erlang code lists:foreach( +erlang code fun(El) -> +erlang code xdb_data(User, Server, El) +erlang code end, Els); +erlang code _ -> +erlang code ok +erlang code end. +erlang blank +erlang blank +erlang code xdb_data(User, Server, {xmlcdata, _CData}) -> +erlang code ok; +erlang code xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) -> +erlang code From = jlib:make_jid(User, Server, ""), +erlang code LServer = jlib:nameprep(Server), +erlang code case xml:get_attr_s("xmlns", Attrs) of +erlang code ?NS_AUTH -> +erlang code Password = xml:get_tag_cdata(El), +erlang code ejabberd_auth:set_password(User, Server, Password), +erlang code ok; +erlang code ?NS_ROSTER -> +erlang code case lists:member(mod_roster_odbc, +erlang code gen_mod:loaded_modules(LServer)) of +erlang code true -> +erlang code catch mod_roster_odbc:set_items(User, Server, El); +erlang code false -> +erlang code catch mod_roster:set_items(User, Server, El) +erlang code end, +erlang code ok; +erlang code ?NS_LAST -> +erlang code TimeStamp = xml:get_attr_s("last", Attrs), +erlang code Status = xml:get_tag_cdata(El), +erlang code case lists:member(mod_last_odbc, +erlang code gen_mod:loaded_modules(LServer)) of +erlang code true -> +erlang code catch mod_last_odbc:store_last_info( +erlang code User, +erlang code Server, +erlang code list_to_integer(TimeStamp), +erlang code Status); +erlang code false -> +erlang code catch mod_last:store_last_info( +erlang code User, +erlang code Server, +erlang code list_to_integer(TimeStamp), +erlang code Status) +erlang code end, +erlang code ok; +erlang code ?NS_VCARD -> +erlang code case lists:member(mod_vcard_odbc, +erlang code gen_mod:loaded_modules(LServer)) of +erlang code true -> +erlang code catch mod_vcard_odbc:process_sm_iq( +erlang code From, +erlang code jlib:make_jid("", Server, ""), +erlang code #iq{type = set, xmlns = ?NS_VCARD, sub_el = El}); +erlang code false -> +erlang code catch mod_vcard:process_sm_iq( +erlang code From, +erlang code jlib:make_jid("", Server, ""), +erlang code #iq{type = set, xmlns = ?NS_VCARD, sub_el = El}) +erlang code end, +erlang code ok; +erlang code "jabber:x:offline" -> +erlang code process_offline(Server, From, El), +erlang code ok; +erlang code XMLNS -> +erlang code case xml:get_attr_s("j_private_flag", Attrs) of +erlang code "1" -> +erlang code catch mod_private:process_sm_iq( +erlang code From, +erlang code jlib:make_jid("", Server, ""), +erlang code #iq{type = set, xmlns = ?NS_PRIVATE, +erlang code sub_el = {xmlelement, "query", [], +erlang code [jlib:remove_attr( +erlang code "j_private_flag", +erlang code jlib:remove_attr("xdbns", El))]}}); +erlang code _ -> +erlang code ?DEBUG("jd2ejd: Unknown namespace \"~s\"~n", [XMLNS]) +erlang code end, +erlang code ok +erlang code end. +erlang blank +erlang blank +erlang code process_offline(Server, To, {xmlelement, _, _, Els}) -> +erlang code LServer = jlib:nameprep(Server), +erlang code lists:foreach(fun({xmlelement, _, Attrs, _} = El) -> +erlang code FromS = xml:get_attr_s("from", Attrs), +erlang code From = case FromS of +erlang code "" -> +erlang code jlib:make_jid("", Server, ""); +erlang code _ -> +erlang code jlib:string_to_jid(FromS) +erlang code end, +erlang code case From of +erlang code error -> +erlang code ok; +erlang code _ -> +erlang code ejabberd_hooks:run(offline_message_hook, +erlang code LServer, +erlang code [From, To, El]) +erlang code end +erlang code end, Els). +erlang blank diff --git a/test/expected_dir/erl1.erl/erlang/blanks b/test/expected_dir/erl1.erl/erlang/blanks deleted file mode 100644 index da2d398..0000000 --- a/test/expected_dir/erl1.erl/erlang/blanks +++ /dev/null @@ -1 +0,0 @@ -14 \ No newline at end of file diff --git a/test/expected_dir/erl1.erl/erlang/code b/test/expected_dir/erl1.erl/erlang/code deleted file mode 100644 index 3057191..0000000 --- a/test/expected_dir/erl1.erl/erlang/code +++ /dev/null @@ -1,161 +0,0 @@ --module(erl1). --author('jason@ohloh.net'). --vsn('$Revision: 1 $ '). --export([import_file/1, -import_dir/1]). --include("random.hrl"). --include("more_random.hrl"). -import_file(File) -> -User = filename:rootname(filename:basename(File)), -Server = filename:basename(filename:dirname(File)), -case (jlib:nodeprep(User) /= error) andalso -(jlib:nameprep(Server) /= error) of -true -> -case file:read_file(File) of -{ok, Text} -> -case xml_stream:parse_element(Text) of -El when element(1, El) == xmlelement -> -case catch process_xdb(User, Server, El) of -{'EXIT', Reason} -> -?ERROR_MSG( -"Error while processing file \"~s\": ~p~n", -[File, Reason]), -{error, Reason}; -_ -> -ok -end; -{error, Reason} -> -?ERROR_MSG("Can't parse file \"~s\": ~p~n", -[File, Reason]), -{error, Reason} -end; -{error, Reason} -> -?ERROR_MSG("Can't read file \"~s\": ~p~n", [File, Reason]), -{error, Reason} -end; -false -> -?ERROR_MSG("Illegal user/server name in file \"~s\"~n", [File]), -{error, "illegal user/server"} -end. -import_dir(Dir) -> -{ok, Files} = file:list_dir(Dir), -MsgFiles = lists:filter( -fun(FN) -> -case string:len(FN) > 4 of -true -> -string:substr(FN, -string:len(FN) - 3) == ".xml"; -_ -> -false -end -end, Files), -lists:foldl( -fun(FN, A) -> -Res = import_file(filename:join([Dir, FN])), -case {A, Res} of -{ok, ok} -> ok; -{ok, _} -> {error, "see aoabberd log for details"}; -_ -> A -end -end, ok, MsgFiles). -process_xdb(User, Server, {xmlelement, Name, _Attrs, Els}) -> -case Name of -"xdb" -> -lists:foreach( -fun(El) -> -xdb_data(User, Server, El) -end, Els); -_ -> -ok -end. -xdb_data(User, Server, {xmlcdata, _CData}) -> -ok; -xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) -> -From = jlib:make_jid(User, Server, ""), -LServer = jlib:nameprep(Server), -case xml:get_attr_s("xmlns", Attrs) of -?NS_AUTH -> -Password = xml:get_tag_cdata(El), -ejabberd_auth:set_password(User, Server, Password), -ok; -?NS_ROSTER -> -case lists:member(mod_roster_odbc, -gen_mod:loaded_modules(LServer)) of -true -> -catch mod_roster_odbc:set_items(User, Server, El); -false -> -catch mod_roster:set_items(User, Server, El) -end, -ok; -?NS_LAST -> -TimeStamp = xml:get_attr_s("last", Attrs), -Status = xml:get_tag_cdata(El), -case lists:member(mod_last_odbc, -gen_mod:loaded_modules(LServer)) of -true -> -catch mod_last_odbc:store_last_info( -User, -Server, -list_to_integer(TimeStamp), -Status); -false -> -catch mod_last:store_last_info( -User, -Server, -list_to_integer(TimeStamp), -Status) -end, -ok; -?NS_VCARD -> -case lists:member(mod_vcard_odbc, -gen_mod:loaded_modules(LServer)) of -true -> -catch mod_vcard_odbc:process_sm_iq( -From, -jlib:make_jid("", Server, ""), -#iq{type = set, xmlns = ?NS_VCARD, sub_el = El}); -false -> -catch mod_vcard:process_sm_iq( -From, -jlib:make_jid("", Server, ""), -#iq{type = set, xmlns = ?NS_VCARD, sub_el = El}) -end, -ok; -"jabber:x:offline" -> -process_offline(Server, From, El), -ok; -XMLNS -> -case xml:get_attr_s("j_private_flag", Attrs) of -"1" -> -catch mod_private:process_sm_iq( -From, -jlib:make_jid("", Server, ""), -#iq{type = set, xmlns = ?NS_PRIVATE, -sub_el = {xmlelement, "query", [], -[jlib:remove_attr( -"j_private_flag", -jlib:remove_attr("xdbns", El))]}}); -_ -> -?DEBUG("jd2ejd: Unknown namespace \"~s\"~n", [XMLNS]) -end, -ok -end. -process_offline(Server, To, {xmlelement, _, _, Els}) -> -LServer = jlib:nameprep(Server), -lists:foreach(fun({xmlelement, _, Attrs, _} = El) -> -FromS = xml:get_attr_s("from", Attrs), -From = case FromS of -"" -> -jlib:make_jid("", Server, ""); -_ -> -jlib:string_to_jid(FromS) -end, -case From of -error -> -ok; -_ -> -ejabberd_hooks:run(offline_message_hook, -LServer, -[From, To, El]) -end -end, Els). diff --git a/test/expected_dir/erl1.erl/erlang/comment b/test/expected_dir/erl1.erl/erlang/comment deleted file mode 100644 index 5a8848b..0000000 --- a/test/expected_dir/erl1.erl/erlang/comment +++ /dev/null @@ -1,14 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : erl1.erl -%%% Author : Jason Allen - kinda - just repurposing random code -%%% Purpose : Test out the erlang parsing -%%% Created : 1/17/2007 by Jason Allen -%%% Id : $Id: erl1.erl 1 2007-17-01 jason $ -%%%---------------------------------------------------------------------- -%% External exports -%%%---------------------------------------------------------------------- -%%% API -%%%---------------------------------------------------------------------- -%%%---------------------------------------------------------------------- -%%% Internal functions -%%%---------------------------------------------------------------------- diff --git a/test/expected_dir/example.R b/test/expected_dir/example.R new file mode 100644 index 0000000..1058247 --- /dev/null +++ b/test/expected_dir/example.R @@ -0,0 +1,200 @@ +r comment # Build a 'graph-like' object having 'nodes' nodes belonging to 'classes' classes. +r comment # Class distribution is given by 'proba', and connectivity probabilities are given +r comment # by 'intraproba' and 'interproba'. +r code generateGraph<-function(nodes,classes,proba=rep(1/classes,classes), +r code intraproba=0.1,crossproba=0.02) +r code { +r code mat_pi=CreateConnectivityMat(classes,intraproba,crossproba) +r code igraph=Fast2SimuleERMG(nodes,proba,mat_pi[1],mat_pi[2]) +r code adjacency=get.adjacency(igraph$graph) +r code cmgraph=list(nodes=nodes,classes=classes,adjacency=adjacency,nodeclasses=igraph$node.classes,proba=proba, +r code intraproba=intraproba,crossproba=crossproba) +r code attr(cmgraph,'class')<-c('cmgraph') +r code cmgraph +r code } +r blank +r comment # Return explicit member names for the different attributes of graph objects. +r code labels.cmgraph<-function(object,...) +r code { +r code c("Nodes","Classes","Adjacency Matrix","Node Classification","Class Probability Distribution","Intra Class Edge Probability","Cross Class Edge Probability") +r code } +r blank +r comment # Override the summmary function for graph objects. +r code summary.cmgraph<-function(object,...) +r code { +r blank +r code cat(c("Nodes : ",object$nodes,"\n", +r code "Edges : ",length(which(object$adjacency!=0)),"\n", +r code "Classes : ",object$classes,"\n", +r code "Class Probability Distribution: ",object$proba,"\n")) +r code } +r blank +r comment # Override the plot function for graph objects. +r code plot.cmgraph<-function(x,...) +r code { +r code RepresentationXGroup(x$adjacency,x$nodeclasses) +r code } +r blank +r comment # Generate covariable data for the graph 'g'. Covariables are associated to vertex data, and +r comment # their values are drawn according to 2 distributions: one for vertices joining nodes of +r comment # the same class, and another for vertices joining nodes of different classes. +r comment # The two distributions have different means but a single standard deviation. +r code generateCovariablesCondZ<-function(g,sameclustermean=0,otherclustermean=2,sigma=1) +r code { +r code mu=CreateMu(g$classes,sameclustermean,otherclustermean) +r code res=SimDataYcondZ(g$nodeclasses,mu,sigma) +r code cmcovars=list(graph=g,sameclustermean=sameclustermean,otherclustermean=otherclustermean,sigma=sigma,mu=mu,y=res) +r code attr(cmcovars,'class')<-c('cmcovarz','cmcovar') +r code cmcovars +r code } +r blank +r comment # Generate covariable data for the graph 'g'. Covariables are associated to vertex data, and +r comment # their values are drawn according to 2 distributions: one for vertices joining nodes of +r comment # the same class, and another for vertices joining nodes of different classes. +r comment # The two distributions have different means but a single standard deviation. +r comment # This function generates two sets of covariables. +r code generateCovariablesCondXZ<-function(g,sameclustermean=c(0,3),otherclustermean=c(2,5),sigma=1) +r code { +r code mux0=CreateMu(g$classes,sameclustermean[1],otherclustermean[1]) +r code mux1=CreateMu(g$classes,sameclustermean[2],otherclustermean[2]) +r code res=SimDataYcondXZ(g$nodeclasses,g$adjacency,mux0,mux1,sigma) +r code cmcovars=list(graph=g,sameclustermean=sameclustermean,otherclustermean=otherclustermean,sigma=sigma,mu=c(mux0,mux1),y=res) +r code attr(cmcovars,'class')<-c('cmcovarxz','cmcovar') +r code cmcovars +r code } +r blank +r blank +r comment # Override the print function for a cleaner covariable output. +r code print.cmcovar<-function(x,...) +r code { +r code cat("Classes : ",x$graph$classes,"\n", +r code "Intra cluster mean: ",x$sameclustermean,"\n", +r code "Cross cluster mean: ",x$otherclustermean,"\n", +r code "Variance : ",x$sigma,"\n", +r code "Covariables :\n",x$y,"\n") +r code } +r blank +r blank +r comment # Perform parameter estimation on 'graph' given the covariables 'covars'. +r code estimateCondZ<-function(graph,covars,maxiterations,initialclasses,selfloops) +r code { +r code res=EMalgorithm(initialclasses,covars$y,graph$adjacency,maxiterations,FALSE,selfloops) +r code cmestimation=list(mean=res$MuEstimated,variance=res$VarianceEstimated,pi=res$PIEstimated,alpha=res$AlphaEstimated,tau=res$TauEstimated,jexpected=res$EJ,graph=graph) +r code attr(cmestimation,'class')<-c('cmestimationz') +r code cmestimation +r code } +r blank +r comment # Private generic estimation function used to allow various call conventions for estimation functions. +r code privateestimate<-function(covars,graph,maxiterations,initialclasses,selfloops,...) UseMethod("privateestimate") +r blank +r comment # Private estimation function used to allow various call conventions for estimation functions. +r comment # Override of generic function for single covariables. +r code privateestimate.cmcovarz<-function(covars,graph,maxiterations,initialclasses,selfloops,...) +r code { +r code res=estimateCondZ(graph,covars,maxiterations,initialclasses,selfloops) +r code attr(res,'class')<-c(attr(res,'class'),'cmestimation') +r code res +r blank +r code } +r blank +r comment # Perform parameter estimation on 'graph' given the covariables 'covars'. +r code estimateCondXZ<-function(graph,covars,maxiterations,initialclasses,selfloops) +r code { +r comment #resSimXZ = EMalgorithmXZ(TauIni,Y2,Adjacente,30,SelfLoop=FALSE) +r code res=EMalgorithmXZ(initialclasses,covars$y,graph$adjacency,maxiterations,selfloops) +r code cmestimation=list(mean=c(res$MuEstimated1,res$MuEstimated2),variance=res$VarianceEstimated,pi=res$PIEstimated,alpha=res$AlphaEstimated,tau=res$TauEstimated,jexpected=res$EJ,graph=graph) +r code attr(cmestimation,'class')<-c('cmestimationxz') +r code cmestimation +r code } +r blank +r comment # Private estimation function used to allow various call conventions for estimation functions. +r comment # Override of generic function for multiple covariables. +r code privateestimate.cmcovarxz<-function(covars,graph,maxiterations,initialclasses,selfloops,...) +r code { +r code res=estimateCondXZ(graph,covars,maxiterations,initialclasses,selfloops) +r code attr(res,'class')<-c(attr(res,'class'),'cmestimation') +r code res +r code } +r blank +r comment # Generic estimation function applicable to graphs with covariables. +r code estimate<-function(graph,covars,...) UseMethod("estimate") +r blank +r comment # Override of the generic estimation function. Performs the actual function dispatch depending on the class of covariables. +r code estimate.cmgraph<-function(graph,covars,maxiterations=20,initialclasses=t(rmultinom(size=1,prob=graph$proba,n=graph$nodes)),selfloops=FALSE,method=NULL,...) +r code { +r code if (length(method) == 0) { +r code res=privateestimate(covars,graph,maxiterations,initialclasses,selfloops,...) +r code } else { +r code res=method(graph,covars,maxiterations,initialclasses,selfloops) +r code attr(res,'class')<-c(attr(res,'class'),'cmestimation') +r code } +r code res +r code } +r blank +r comment # Override of the generic pliot function for estimation results. +r code plot.cmestimation<-function(x,...) +r code { +r code par(mfrow = c(1,2)) +r code plot(x$jexpected) +r code title("Expected value of J: Convergence criterion") +r blank +r code map=MAP(x$tau) +r code gplot(x$graph$adjacency,vertex.col=map$node.classes+2) +r code title("Network with estimated classes") +r blank +r code } +r blank +r comment # Generic private ICL computation function for graphs and covariables. +r code privatecomputeICL<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) UseMethod("privatecomputeICL") +r blank +r blank +r comment # Private ICL computation function for graphs with single covariables. +r code privatecomputeICL.cmcovarz<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) +r code { +r code res=ICL(X=graph$adjacency,Y=covars$y,Qmin=qmin,Qmax=qmax,loop=loops,NbIteration=maxiterations,SelfLoop=selfloops,Plot=FALSE) +r code attr(res,'class')<-c('cmiclz') +r code res +r blank +r code } +r blank +r comment # Private ICL computation function for graphs with multiple covariables. +r code privatecomputeICL.cmcovarxz<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) +r code { +r code res=ICL(X=graph$adjacency,Y=covars$y,Qmin=qmin,Qmax=qmax,loop=loops,NbIteration=maxiterations,SelfLoop=selfloops,Plot=FALSE) +r code attr(res,'class')<-c('cmiclxz') +r code res +r code } +r blank +r blank +r comment # Generic public ICL computation function applicable to graph objects. +r code computeICL<-function(graph,covars,qmin,qmax,...) UseMethod("computeICL") +r blank +r comment # Override of ICL computation function applicable to graph objects. +r comment # Performs the actual method dispatch to private functions depending on the type of covariables. +r code computeICL.cmgraph<-function(graph,covars,qmin,qmax,loops=10,maxiterations=20,selfloops=FALSE,...) +r code { +r code res=privatecomputeICL(covars,graph,qmin,qmax,loops,maxiterations,selfloops) +r code res$qmin=qmin +r code res$qmax=qmax +r code res$graph=graph +r code res$covars=covars +r code attr(res,'class')<-c(attr(res,'class'),'cmicl') +r code res +r code } +r blank +r comment # Override of the plot function for results of ICL computation. +r code plot.cmicl<-function(x,...) +r code { +r code par(mfrow = c(1,2)) +r code result=x$iclvalues +r code maxi=which(max(result)==result) +r code plot(seq(x$qmin,x$qmax),result,type="b",xlab="Number of classes",ylab="ICL value") +r code points(maxi+x$qmin-1,result[maxi],col="red") +r code title("ICL curve") +r code best=x$EMestimation[[maxi+x$qmin-1]] +r code tau=best$TauEstimated +r code map=MAP(tau) +r code gplot(x$graph$adjacency,vertex.col=map$node.classes+2) +r code title("Network with estimated classes") +r code } +r blank diff --git a/test/expected_dir/example.qml b/test/expected_dir/example.qml new file mode 100644 index 0000000..ab96abc --- /dev/null +++ b/test/expected_dir/example.qml @@ -0,0 +1,17 @@ +qml comment // Just an example of QML file... +qml blank +qml code import QtQuick 2.0 +qml blank +qml code Rectangle { +qml code width: 200 +qml code height: 200 +qml code color: "crimson" +qml blank +qml code MouseArea { +qml code anchors.fill: parent +qml code onClicked: { +qml comment // Was clicked +qml code Qt.quit(); +qml code } +qml code } +qml code } diff --git a/test/expected_dir/example.rkt b/test/expected_dir/example.rkt new file mode 100644 index 0000000..9c3f2e4 --- /dev/null +++ b/test/expected_dir/example.rkt @@ -0,0 +1,12 @@ +racket comment ;; language declaration commented out until someone extends the +racket comment ;; parser to support it: +racket blank +racket comment ;; #lang racket +racket blank +racket comment ;; Report each unique line from stdin +racket code (let ([saw (make-hash)]) +racket code (for ([line (in-lines)]) +racket code (unless (hash-ref saw line #f) +racket code (displayln line)) +racket code (hash-set! saw line #t))) +racket blank diff --git a/test/expected_dir/example.xsl b/test/expected_dir/example.xsl new file mode 100644 index 0000000..be18ba2 --- /dev/null +++ b/test/expected_dir/example.xsl @@ -0,0 +1,17 @@ +xslt code +xslt code +xslt blank +xslt comment +xslt code +xslt code +xslt code +xslt code sample webpage +xslt code +xslt code +xslt code +xslt comment +xslt code comment in HTML +xslt code +xslt code +xslt code +xslt code diff --git a/test/expected_dir/example.xsl/xslt/blanks b/test/expected_dir/example.xsl/xslt/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/example.xsl/xslt/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/example.xsl/xslt/code b/test/expected_dir/example.xsl/xslt/code deleted file mode 100644 index 21b2504..0000000 --- a/test/expected_dir/example.xsl/xslt/code +++ /dev/null @@ -1,14 +0,0 @@ - - - - - -sample webpage - - - - comment in HTML - - - - diff --git a/test/expected_dir/example.xsl/xslt/comment b/test/expected_dir/example.xsl/xslt/comment deleted file mode 100644 index a82f20c..0000000 --- a/test/expected_dir/example.xsl/xslt/comment +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/test/expected_dir/factor1.factor b/test/expected_dir/factor1.factor new file mode 100644 index 0000000..a6c1180 --- /dev/null +++ b/test/expected_dir/factor1.factor @@ -0,0 +1,14 @@ +factor comment ! This is a comment +factor comment ! Factor syntax is very simple, it just contains words separated by spaces +factor comment ! '!' is a line comment word +factor comment ! "whatever" is a string word +factor code USING: kernel io ; ! This is a vocabulary inclusion word +factor code IN: testing +factor blank +factor code : test-string ( -- ) +factor code "this is a string" print ; +factor blank +factor code : test ( x -- y ) ! Parenthesis define a stack effect declaration +factor code dup swap drop ; +factor blank +factor code MAIN: test diff --git a/test/expected_dir/factor1.factor/factor/blanks b/test/expected_dir/factor1.factor/factor/blanks deleted file mode 100644 index e440e5c..0000000 --- a/test/expected_dir/factor1.factor/factor/blanks +++ /dev/null @@ -1 +0,0 @@ -3 \ No newline at end of file diff --git a/test/expected_dir/factor1.factor/factor/code b/test/expected_dir/factor1.factor/factor/code deleted file mode 100644 index d0b7ee4..0000000 --- a/test/expected_dir/factor1.factor/factor/code +++ /dev/null @@ -1,7 +0,0 @@ -USING: kernel io ; ! This is a vocabulary inclusion word -IN: testing -: test-string ( -- ) -"this is a string" print ; -: test ( x -- y ) ! Parenthesis define a stack effect declaration -dup swap drop ; -MAIN: test diff --git a/test/expected_dir/factor1.factor/factor/comment b/test/expected_dir/factor1.factor/factor/comment deleted file mode 100644 index e23ee5f..0000000 --- a/test/expected_dir/factor1.factor/factor/comment +++ /dev/null @@ -1,4 +0,0 @@ -! This is a comment -! Factor syntax is very simple, it just contains words separated by spaces -! '!' is a line comment word -! "whatever" is a string word diff --git a/test/expected_dir/fb.js b/test/expected_dir/fb.js new file mode 100644 index 0000000..0f7000e --- /dev/null +++ b/test/expected_dir/fb.js @@ -0,0 +1,9 @@ +javascript code function escapeHTML(value) +javascript code { +javascript code return String(value).replace(/[<>&"']/g, replaceChars); +javascript code } +javascript blank +javascript code window.onerror = onError; +javascript blank +javascript code if (document.documentElement.getAttribute("debug") == "true") +javascript code toggleConsole(true); diff --git a/test/expected_dir/foo.coffee b/test/expected_dir/foo.coffee new file mode 100644 index 0000000..d121da7 --- /dev/null +++ b/test/expected_dir/foo.coffee @@ -0,0 +1,26 @@ +coffeescript comment # A CoffeeScript parser test file +coffeescript blank +coffeescript code simple_code = true +coffeescript blank +coffeescript comment ### +coffeescript comment A multi-line block comment +coffeescript comment begins and ends with three hash marks +coffeescript comment ### +coffeescript blank +coffeescript code multi_line_string = ''' +coffeescript code A multi-line string constant ("here doc") +coffeescript code begins and ends with three quote marks +coffeescript code ''' +coffeescript blank +coffeescript code foo = "A string can wrap across multiple lines +coffeescript code and may contain #{interpolated_values}" +coffeescript blank +coffeescript blank +coffeescript comment ### +coffeescript comment A clever parser can use Ohcount's "Polyglot" feature treat the +coffeescript comment following as embedded JavaScript. +coffeescript comment ### +javascript code embedded_js = `function() { +javascript code return [document.title, "Hello JavaScript"].join(": "); +coffeescript code }` +coffeescript blank diff --git a/test/expected_dir/foo.dtx b/test/expected_dir/foo.dtx new file mode 100644 index 0000000..1275756 --- /dev/null +++ b/test/expected_dir/foo.dtx @@ -0,0 +1,9 @@ +tex_dtx code \begin{document} +tex_dtx code \texbf Hello world +tex_dtx blank +tex_dtx blank +tex_dtx code % \acommand +tex_dtx code % \anothercommand +tex_dtx comment %% sample comment +tex_dtx blank +tex_dtx code \end{document} diff --git a/test/expected_dir/foo.ebuild b/test/expected_dir/foo.ebuild new file mode 100644 index 0000000..dbb6cca --- /dev/null +++ b/test/expected_dir/foo.ebuild @@ -0,0 +1,21 @@ +ebuild comment # This is an ebuild. +ebuild comment # Distributed under the terms of the GNU General Public License v2 +ebuild comment # $Header: $ +ebuild blank +ebuild code DESCRIPTION="An ebuild" +ebuild code HOMEPAGE="" +ebuild code SRC_URI="" +ebuild blank +ebuild code LICENSE="" +ebuild code SLOT="0" +ebuild code KEYWORDS="~x86" +ebuild code IUSE="" +ebuild blank +ebuild code DEPEND="" +ebuild code RDEPEND="" +ebuild blank +ebuild code pkg_setup() { +ebuild comment # This is foo +ebuild code einfo "This is foo" +ebuild code } +ebuild blank diff --git a/test/expected_dir/foo.ebuild/ebuild/blanks b/test/expected_dir/foo.ebuild/ebuild/blanks deleted file mode 100644 index 7813681..0000000 --- a/test/expected_dir/foo.ebuild/ebuild/blanks +++ /dev/null @@ -1 +0,0 @@ -5 \ No newline at end of file diff --git a/test/expected_dir/foo.ebuild/ebuild/code b/test/expected_dir/foo.ebuild/ebuild/code deleted file mode 100644 index 6f0809e..0000000 --- a/test/expected_dir/foo.ebuild/ebuild/code +++ /dev/null @@ -1,12 +0,0 @@ -DESCRIPTION="An ebuild" -HOMEPAGE="" -SRC_URI="" -LICENSE="" -SLOT="0" -KEYWORDS="~x86" -IUSE="" -DEPEND="" -RDEPEND="" -pkg_setup() { -einfo "This is foo" -} diff --git a/test/expected_dir/foo.ebuild/ebuild/comment b/test/expected_dir/foo.ebuild/ebuild/comment deleted file mode 100644 index a096ab8..0000000 --- a/test/expected_dir/foo.ebuild/ebuild/comment +++ /dev/null @@ -1,4 +0,0 @@ -# This is an ebuild. -# Distributed under the terms of the GNU General Public License v2 -# $Header: $ -# This is foo diff --git a/test/expected_dir/foo.exheres-0 b/test/expected_dir/foo.exheres-0 new file mode 100644 index 0000000..ff3e5a7 --- /dev/null +++ b/test/expected_dir/foo.exheres-0 @@ -0,0 +1,20 @@ +exheres comment # This is an exheres. +exheres blank +exheres code require subversion bash-completion eutils flag-o-matic +exheres blank +exheres code DESCRIPTION="An exheres" +exheres code HOMEPAGE="http://example.org/" +exheres code SRC_URI="" +exheres blank +exheres code MYOPTIONS="monkey" +exheres code LICENSE="GPL-2" +exheres code SLOT="0" +exheres code PLATFORMS="~amd64 ~ia64 ~x86" +exheres blank +exheres code DEPENDENCIES="" +exheres blank +exheres code src_prepare() { +exheres code default +exheres code ./autogen.bash || die "autogen.bash failed" +exheres code } +exheres blank diff --git a/test/expected_dir/foo.exheres-0/exheres/blanks b/test/expected_dir/foo.exheres-0/exheres/blanks deleted file mode 100644 index 62f9457..0000000 --- a/test/expected_dir/foo.exheres-0/exheres/blanks +++ /dev/null @@ -1 +0,0 @@ -6 \ No newline at end of file diff --git a/test/expected_dir/foo.exheres-0/exheres/code b/test/expected_dir/foo.exheres-0/exheres/code deleted file mode 100644 index 622f684..0000000 --- a/test/expected_dir/foo.exheres-0/exheres/code +++ /dev/null @@ -1,13 +0,0 @@ -require subversion bash-completion eutils flag-o-matic -DESCRIPTION="An exheres" -HOMEPAGE="http://example.org/" -SRC_URI="" -MYOPTIONS="monkey" -LICENSE="GPL-2" -SLOT="0" -PLATFORMS="~amd64 ~ia64 ~x86" -DEPENDENCIES="" -src_prepare() { -default -./autogen.bash || die "autogen.bash failed" -} diff --git a/test/expected_dir/foo.exheres-0/exheres/comment b/test/expected_dir/foo.exheres-0/exheres/comment deleted file mode 100644 index dbb04ce..0000000 --- a/test/expected_dir/foo.exheres-0/exheres/comment +++ /dev/null @@ -1 +0,0 @@ -# This is an exheres. diff --git a/test/expected_dir/foo.glsl b/test/expected_dir/foo.glsl new file mode 100644 index 0000000..97f3b9a --- /dev/null +++ b/test/expected_dir/foo.glsl @@ -0,0 +1,4 @@ +glsl comment // GLSL vertex shader +glsl code void main() { +glsl code gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; +glsl code } \ No newline at end of file diff --git a/test/expected_dir/foo.nsh b/test/expected_dir/foo.nsh new file mode 100644 index 0000000..0eddb8b --- /dev/null +++ b/test/expected_dir/foo.nsh @@ -0,0 +1,17 @@ +nsis comment ; NSIS "header" libraries can be in .nsh files. +nsis comment /* Copyright some time +nsis comment * never +nsis comment * and not much of that either +nsis comment "still a comment" +nsis comment */ +nsis blank +nsis code !macro SillyMacro Param1 +nsis comment ; ... Because we can ;-) +nsis code !error "Why did you call this macro, ${Param1}? That was silly." +nsis code !macroend +nsis blank +nsis code Function Die +nsis comment # Likewise, because we can. +nsis code DetailPrint "Aarrrrggghh! I died." +nsis code Quit +nsis code FunctionEnd diff --git a/test/expected_dir/foo.nsi b/test/expected_dir/foo.nsi new file mode 100644 index 0000000..243329e --- /dev/null +++ b/test/expected_dir/foo.nsi @@ -0,0 +1,15 @@ +nsis comment ; some nsis code +nsis comment /* +nsis comment * lorem +nsis comment ipsum +nsis comment dolor sit amet etcetera +nsis comment */ +nsis blank +nsis code !include LogicLib.nsh +nsis code OutFile foo.exe +nsis blank +nsis code Section +nsis code IfFileExists ${__FILE__} 0 +2 ; comments can be inline +nsis comment # Use of ; in a string on the next line +nsis code MessageBox MB_OK "You moved this installer file; you shouldn't do that ;-)" +nsis code SectionEnd diff --git a/test/expected_dir/foo.tex b/test/expected_dir/foo.tex new file mode 100644 index 0000000..2115445 --- /dev/null +++ b/test/expected_dir/foo.tex @@ -0,0 +1,8 @@ +tex code \begin{document} +tex code \texbf Hello world +tex blank +tex blank +tex comment % +tex comment % sample comment +tex blank +tex code \end{document} diff --git a/test/expected_dir/foo.tex/tex/blanks b/test/expected_dir/foo.tex/tex/blanks deleted file mode 100644 index e440e5c..0000000 --- a/test/expected_dir/foo.tex/tex/blanks +++ /dev/null @@ -1 +0,0 @@ -3 \ No newline at end of file diff --git a/test/expected_dir/foo.tex/tex/code b/test/expected_dir/foo.tex/tex/code deleted file mode 100644 index aec1334..0000000 --- a/test/expected_dir/foo.tex/tex/code +++ /dev/null @@ -1,3 +0,0 @@ -\begin{document} -\texbf Hello world -\end{document} diff --git a/test/expected_dir/foo.tex/tex/comment b/test/expected_dir/foo.tex/tex/comment deleted file mode 100644 index 1a8caa7..0000000 --- a/test/expected_dir/foo.tex/tex/comment +++ /dev/null @@ -1,2 +0,0 @@ -% -% sample comment diff --git a/test/expected_dir/foo.vim b/test/expected_dir/foo.vim new file mode 100644 index 0000000..4322100 --- /dev/null +++ b/test/expected_dir/foo.vim @@ -0,0 +1,21 @@ +vim comment " Vim syntax file +vim comment " Language: Test file for ohcount +vim comment " Author: Ciaran McCreesh +vim comment " +vim comment " This is a test vim syntax file for ohcount. +vim comment " +vim blank +vim code if &compatible || v:version < 700 +vim code finish +vim code endif +vim blank +vim code if exists("b:current_syntax") +vim code finish +vim code endif +vim blank +vim comment " This is a comment. There are many like it, but this one is mine. +vim code syn region GiantSpaceMonkey start=/^\s*#/ end=/$/ +vim code hi def link GiantSpaceMonkey Comment +vim blank +vim code let b:current_syntax = "ohcount-test" +vim blank diff --git a/test/expected_dir/foo.vim/vim/blanks b/test/expected_dir/foo.vim/vim/blanks deleted file mode 100644 index 7813681..0000000 --- a/test/expected_dir/foo.vim/vim/blanks +++ /dev/null @@ -1 +0,0 @@ -5 \ No newline at end of file diff --git a/test/expected_dir/foo.vim/vim/code b/test/expected_dir/foo.vim/vim/code deleted file mode 100644 index 8f97fe5..0000000 --- a/test/expected_dir/foo.vim/vim/code +++ /dev/null @@ -1,9 +0,0 @@ -if &compatible || v:version < 700 -finish -endif -if exists("b:current_syntax") -finish -endif -syn region GiantSpaceMonkey start=/^\s*#/ end=/$/ -hi def link GiantSpaceMonkey Comment -let b:current_syntax = "ohcount-test" diff --git a/test/expected_dir/foo.vim/vim/comment b/test/expected_dir/foo.vim/vim/comment deleted file mode 100644 index 6b55283..0000000 --- a/test/expected_dir/foo.vim/vim/comment +++ /dev/null @@ -1,7 +0,0 @@ -" Vim syntax file -" Language: Test file for ohcount -" Author: Ciaran McCreesh -" -" This is a test vim syntax file for ohcount. -" -" This is a comment. There are many like it, but this one is mine. diff --git a/test/expected_dir/foo_glsl.vert b/test/expected_dir/foo_glsl.vert new file mode 100644 index 0000000..48dafda --- /dev/null +++ b/test/expected_dir/foo_glsl.vert @@ -0,0 +1,43 @@ +glsl comment // from OGRE3D's skinningTwoWeightsShadowCasterVp.glsl +glsl comment // Example GLSL program for skinning with two bone weights per vertex +glsl blank +glsl code attribute vec4 vertex; +glsl code attribute vec4 uv0; +glsl code attribute vec4 blendIndices; +glsl code attribute vec4 blendWeights; +glsl blank +glsl comment // 3x4 matrix, passed as vec4's for compatibility with GL 2.0 +glsl comment // GL 2.0 supports 3x4 matrices +glsl comment // Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +glsl code uniform vec4 worldMatrix3x4Array[72]; +glsl code uniform mat4 viewProjectionMatrix; +glsl code uniform vec4 ambient; +glsl blank +glsl code void main() +glsl code { +glsl code vec3 blendPos = vec3(0,0,0); +glsl blank +glsl code for (int bone = 0; bone < 2; ++bone) +glsl code { +glsl comment // perform matrix multiplication manually since no 3x4 matrices +glsl comment // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first +glsl code int idx = int(blendIndices[bone]) * 3; +glsl comment // ATI GLSL compiler can't handle unrolling the loop so do it manually +glsl comment // ATI GLSL has better performance when mat4 is used rather than using individual dot product +glsl comment // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign +glsl code mat4 worldMatrix; +glsl code worldMatrix[0] = worldMatrix3x4Array[idx]; +glsl code worldMatrix[1] = worldMatrix3x4Array[idx + 1]; +glsl code worldMatrix[2] = worldMatrix3x4Array[idx + 2]; +glsl code worldMatrix[3] = vec4(0); +glsl comment // now weight this into final +glsl code blendPos += (vertex * worldMatrix).xyz * blendWeights[bone]; +glsl code } +glsl blank +glsl comment // apply view / projection to position +glsl code gl_Position = viewProjectionMatrix * vec4(blendPos, 1); +glsl blank +glsl code gl_FrontSecondaryColor = vec4(0,0,0,0); +glsl code gl_FrontColor = ambient; +glsl code gl_TexCoord[0] = uv0; +glsl code } diff --git a/test/expected_dir/forth.4th b/test/expected_dir/forth.4th new file mode 100644 index 0000000..e7f5ab5 --- /dev/null +++ b/test/expected_dir/forth.4th @@ -0,0 +1,7 @@ +forth comment \ Sample Forth code +forth blank +forth comment ( This is a comment +forth comment spanning multiple lines ) +forth blank +forth code : somedefinition ; +forth blank diff --git a/test/expected_dir/fortranfixed.f b/test/expected_dir/fortranfixed.f new file mode 100644 index 0000000..0dfeb11 --- /dev/null +++ b/test/expected_dir/fortranfixed.f @@ -0,0 +1,12 @@ +fortranfixed comment C Just a comment, whee. +fortranfixed code program foo +fortranfixed blank +fortranfixed comment C Many languages seem to count split lines as multiple lines, +fortranfixed comment C so we should, too. +fortranfixed code write (*,*) 1 +fortranfixed code + + 1 +fortranfixed blank +fortranfixed comment C And I've never seen Fortran code that wraps strings; I'm +fortranfixed comment C not even sure fixed form allows it. +fortranfixed code write (*,*) 'So we don''t bother testing odd string foo.' +fortranfixed code end diff --git a/test/expected_dir/fortranfixed.f/fortranfixed/blanks b/test/expected_dir/fortranfixed.f/fortranfixed/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/fortranfixed.f/fortranfixed/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/fortranfixed.f/fortranfixed/code b/test/expected_dir/fortranfixed.f/fortranfixed/code deleted file mode 100644 index 70b8166..0000000 --- a/test/expected_dir/fortranfixed.f/fortranfixed/code +++ /dev/null @@ -1,5 +0,0 @@ -program foo -write (*,*) 1 -+ + 1 -write (*,*) 'So we don''t bother testing odd string foo.' -end diff --git a/test/expected_dir/fortranfixed.f/fortranfixed/comment b/test/expected_dir/fortranfixed.f/fortranfixed/comment deleted file mode 100644 index df99f9c..0000000 --- a/test/expected_dir/fortranfixed.f/fortranfixed/comment +++ /dev/null @@ -1,5 +0,0 @@ -C Just a comment, whee. -C Many languages seem to count split lines as multiple lines, -C so we should, too. -C And I've never seen Fortran code that wraps strings; I'm -C not even sure fixed form allows it. diff --git a/test/expected_dir/fortranfree.f b/test/expected_dir/fortranfree.f new file mode 100644 index 0000000..cee279b --- /dev/null +++ b/test/expected_dir/fortranfree.f @@ -0,0 +1,18 @@ +fortranfree comment ! -*- F90 -*- +fortranfree comment ! Just a comment, whee. +fortranfree code program foofree +fortranfree code integer:: c +fortranfree blank +fortranfree comment ! Many languages seem to count split lines as multiple lines, +fortranfree comment ! so we should, too. +fortranfree code write (*,*) 1 & +fortranfree code & + 1 +fortranfree blank +fortranfree code C = 1 ! Not a comment. +fortranfree blank +fortranfree comment ! And I've never seen Fortran code that wraps strings; I'm +fortranfree comment ! not even sure fixed form allows it. +fortranfree code write (*,*) 'But we might as well test for it in& +fortranfree code & free format.' +fortranfree blank +fortranfree code end diff --git a/test/expected_dir/fortranfree.f/fortranfree/blanks b/test/expected_dir/fortranfree.f/fortranfree/blanks deleted file mode 100644 index bf0d87a..0000000 --- a/test/expected_dir/fortranfree.f/fortranfree/blanks +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/test/expected_dir/fortranfree.f/fortranfree/code b/test/expected_dir/fortranfree.f/fortranfree/code deleted file mode 100644 index 7f06fd1..0000000 --- a/test/expected_dir/fortranfree.f/fortranfree/code +++ /dev/null @@ -1,8 +0,0 @@ -program foofree -integer:: c -write (*,*) 1 & -& + 1 -C = 1 ! Not a comment. -write (*,*) 'But we might as well test for it in& -& free format.' -end diff --git a/test/expected_dir/fortranfree.f/fortranfree/comment b/test/expected_dir/fortranfree.f/fortranfree/comment deleted file mode 100644 index 1fc32e7..0000000 --- a/test/expected_dir/fortranfree.f/fortranfree/comment +++ /dev/null @@ -1,6 +0,0 @@ -! -*- F90 -*- -! Just a comment, whee. -! Many languages seem to count split lines as multiple lines, -! so we should, too. -! And I've never seen Fortran code that wraps strings; I'm -! not even sure fixed form allows it. diff --git a/test/expected_dir/frx1.frx b/test/expected_dir/frx1.frx new file mode 100644 index 0000000..c8331c6 --- /dev/null +++ b/test/expected_dir/frx1.frx @@ -0,0 +1,60 @@ +visualbasic code VERSION 5.00 +visualbasic code Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" +visualbasic code Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" +visualbasic code Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX" +visualbasic code Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX" +visualbasic code Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" +visualbasic code Begin VB.Form frmMain +visualbasic code BorderStyle = 1 'Fixed Single +visualbasic code ClientHeight = 6555 +visualbasic code ClientLeft = 150 +visualbasic code ClientTop = 435 +visualbasic code ClientWidth = 10620 +visualbasic code LinkTopic = "Form1" +visualbasic code MaxButton = 0 'False +visualbasic code MinButton = 0 'False +visualbasic code ScaleHeight = 6555 +visualbasic code ScaleWidth = 10620 +visualbasic code StartUpPosition = 3 'Windows Default +visualbasic code Attribute VB_Name = "frmMain" +visualbasic code Attribute VB_GlobalNameSpace = False +visualbasic code Attribute VB_Creatable = False +visualbasic code Attribute VB_PredeclaredId = True +visualbasic code Attribute VB_Exposed = False +visualbasic comment '--------------------------------------------------------------------------- +visualbasic comment ' +visualbasic comment ' SOURCE FILE NAME: Demo.frm +visualbasic comment ' +visualbasic comment ' SAMPLE: Visual Basic Demo with user interface for the sample modules +visualbasic comment ' +visualbasic comment ' For more information about samples, refer to the README file. +visualbasic comment ' +visualbasic comment '--------------------------------------------------------------------------- +visualbasic blank +visualbasic code Option Explicit +visualbasic blank +visualbasic code Private con As ADODB.Connection +visualbasic code Private rst As ADODB.Recordset +visualbasic code Private strMsgText As String +visualbasic code Private wShowInstructions As Integer +visualbasic blank +visualbasic comment 'This procedure calls ConnectOLEDB() in the module dbConn to get +visualbasic comment 'a connection object. +visualbasic code Private Sub cmdConnectOLEDB_Click() +visualbasic comment 'define the error handler +visualbasic comment ' On Error GoTo cmdConnectOLEDB_Error +visualbasic blank +visualbasic comment 'connect to database +visualbasic code Set con = ConnectOLEDB() +visualbasic blank +visualbasic comment 'generate a message of success +visualbasic code sbrStatus.Panels(1).Text = "Connect to sample database succeeded!" +visualbasic blank +visualbasic comment 'config status of the buttons +visualbasic code EnableButtons +visualbasic blank +visualbasic comment 'show instructions +visualbasic code If wShowInstructions = vbYes Then +visualbasic code ShowConnectionInstruction +visualbasic code End If +visualbasic code End Sub diff --git a/test/expected_dir/frx1.frx/visualbasic/blanks b/test/expected_dir/frx1.frx/visualbasic/blanks deleted file mode 100644 index c793025..0000000 --- a/test/expected_dir/frx1.frx/visualbasic/blanks +++ /dev/null @@ -1 +0,0 @@ -7 \ No newline at end of file diff --git a/test/expected_dir/frx1.frx/visualbasic/code b/test/expected_dir/frx1.frx/visualbasic/code deleted file mode 100644 index d0fa5b8..0000000 --- a/test/expected_dir/frx1.frx/visualbasic/code +++ /dev/null @@ -1,36 +0,0 @@ -VERSION 5.00 -Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" -Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" -Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX" -Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX" -Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" -Begin VB.Form frmMain -BorderStyle = 1 'Fixed Single -ClientHeight = 6555 -ClientLeft = 150 -ClientTop = 435 -ClientWidth = 10620 -LinkTopic = "Form1" -MaxButton = 0 'False -MinButton = 0 'False -ScaleHeight = 6555 -ScaleWidth = 10620 -StartUpPosition = 3 'Windows Default -Attribute VB_Name = "frmMain" -Attribute VB_GlobalNameSpace = False -Attribute VB_Creatable = False -Attribute VB_PredeclaredId = True -Attribute VB_Exposed = False -Option Explicit -Private con As ADODB.Connection -Private rst As ADODB.Recordset -Private strMsgText As String -Private wShowInstructions As Integer -Private Sub cmdConnectOLEDB_Click() -Set con = ConnectOLEDB() -sbrStatus.Panels(1).Text = "Connect to sample database succeeded!" -EnableButtons -If wShowInstructions = vbYes Then -ShowConnectionInstruction -End If -End Sub diff --git a/test/expected_dir/frx1.frx/visualbasic/comment b/test/expected_dir/frx1.frx/visualbasic/comment deleted file mode 100644 index fc9649a..0000000 --- a/test/expected_dir/frx1.frx/visualbasic/comment +++ /dev/null @@ -1,17 +0,0 @@ -'--------------------------------------------------------------------------- -' -' SOURCE FILE NAME: Demo.frm -' -' SAMPLE: Visual Basic Demo with user interface for the sample modules -' -' For more information about samples, refer to the README file. -' -'--------------------------------------------------------------------------- -'This procedure calls ConnectOLEDB() in the module dbConn to get -'a connection object. -'define the error handler -' On Error GoTo cmdConnectOLEDB_Error -'connect to database -'generate a message of success -'config status of the buttons -'show instructions diff --git a/test/expected_dir/fs1.fs b/test/expected_dir/fs1.fs new file mode 100644 index 0000000..2f632bb --- /dev/null +++ b/test/expected_dir/fs1.fs @@ -0,0 +1,51 @@ +fsharp comment (*************************************************************************** +fsharp comment * +fsharp comment * The Parser is free software: you can redistribute it and/or modify +fsharp comment * it under the terms of the GNU Lesser General Public License as published by +fsharp comment * the Free Software Foundation, either version 3 of the License, or +fsharp comment * (at your option) any later version. +fsharp comment * +fsharp comment ***************************************************************************) +fsharp blank +fsharp code namespace Tags +fsharp blank +fsharp code open System +fsharp code open System.Reflection; +fsharp code open System.Runtime.CompilerServices; +fsharp code open System.Runtime.InteropServices; +fsharp blank +fsharp code module internal Filter = +fsharp blank +fsharp code let FILTER_VARIABLE_NAME = "$filter" +fsharp blank +fsharp code type FilterNode(provider, token, filter: FilterExpression, node_list) = +fsharp code inherit TagNode(provider, token) +fsharp blank +fsharp code override this.walk manager walker = +fsharp code let reader = +fsharp code new NDjango.ASTWalker.Reader (manager, {walker with parent=None; nodes=node_list; context=walker.context}) +fsharp code match filter.ResolveForOutput manager +fsharp code {walker with context=walker.context.add(FILTER_VARIABLE_NAME, (reader.ReadToEnd():>obj))} +fsharp code with +fsharp code | Some w -> w +fsharp code | None -> walker +fsharp blank +fsharp comment /// Filters the contents of the block through variable filters. +fsharp comment /// +fsharp comment /// Filters can also be piped through each other, and they can have +fsharp comment /// arguments -- just like in variable syntax. +fsharp comment /// +fsharp comment /// Sample usage:: +fsharp comment /// +fsharp comment /// {% filter force_escape|lower %} +fsharp comment /// This text will be HTML-escaped, and will appear in lowercase. +fsharp comment /// {% endfilter %} +fsharp code type FilterTag() = +fsharp code interface ITag with +fsharp code member this.Perform token provider tokens = +fsharp code match token.Args with +fsharp code | filter::[] -> +fsharp code let filter_expr = new FilterExpression(provider, Block token, FILTER_VARIABLE_NAME + "|" + filter) +fsharp code let node_list, remaining = (provider :?> IParser).Parse (Some token) tokens ["endfilter"] +fsharp code (new FilterNode(provider, token, filter_expr, node_list) :> INodeImpl), remaining +fsharp code | _ -> raise (SyntaxError ("'filter' tag requires one argument")) diff --git a/test/expected_dir/grace.grace b/test/expected_dir/grace.grace new file mode 100644 index 0000000..2cc0a16 --- /dev/null +++ b/test/expected_dir/grace.grace @@ -0,0 +1,46 @@ +grace comment ////////////////////////////////////////////////// +grace comment // Sample Grace code +grace blank +grace code import "parsers-test" as parsers +grace blank +grace code class exports { +grace code inherit parsers.exports +grace comment //BEGINGRAMMAR +grace comment // top level +grace code def program = rule {codeSequence ~ rep(ws) ~ end} +grace code def codeSequence = rule { repdel((declaration | statement | empty), semicolon) } +grace code def hashLine = rule { (symbol "#") ~ rep(anyChar | space) ~ (newLine | end) } +grace blank +grace comment // def comment = +grace blank +grace comment //def oldClassDeclaration = rule { classId ~ identifier ~ lBrace ~ +grace comment // opt(genericFormals ~ blockFormals ~ arrow) ~ codeSequence ~ rBrace } +grace blank +grace code def typeOpExpression = rule { rep1sep(basicTypeExpression, typeOp) } +grace blank +grace code def typeOpExpression = rule { +grace code var otherOperator +grace code basicTypeExpression ~ opt(ws) ~ +grace code opt( guard(typeOp, { s -> otherOperator:= s; +grace code true }) ~ rep1sep(basicTypeExpression ~ opt(ws), +grace code guard(typeOp, { s -> s == otherOperator }) +grace code ) +grace code ) +grace code } +grace blank +grace comment // "literals" +grace code def literal = rule { stringLiteral | selfLiteral | blockLiteral | numberLiteral | objectLiteral | lineupLiteral | typeLiteral } +grace blank +grace comment // terminals +grace code def backslash = token "\\" // doesn't belong here, doesn't work if left below! +grace blank +grace code def colon = rule {both(symbol ":", not(assign))} +grace code def newLine = symbol "\n" +grace code def lParen = symbol "(" +grace code def rParen = symbol ")" +grace blank +grace code def reservedOp = rule {assign | equals | dot | arrow | colon | semicolon} // this is not quite right +grace blank +grace comment //ENDGRAMMAR +grace code } +grace blank diff --git a/test/expected_dir/groovy1.groovy b/test/expected_dir/groovy1.groovy new file mode 100644 index 0000000..438f2b4 --- /dev/null +++ b/test/expected_dir/groovy1.groovy @@ -0,0 +1,9 @@ +groovy comment //hello.groovy +groovy code println "hello, world" +groovy code for (arg in this.args ) { +groovy code println "Argument:" + arg; +groovy code } +groovy comment // this is a comment +groovy comment /* a block comment, commenting out an alternative to above: +groovy comment this.args.each{ arg -> println "hello, ${arg}"} +groovy comment */ diff --git a/test/expected_dir/groovy1.groovy/groovy/blanks b/test/expected_dir/groovy1.groovy/groovy/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/groovy1.groovy/groovy/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/groovy1.groovy/groovy/code b/test/expected_dir/groovy1.groovy/groovy/code deleted file mode 100644 index b881b63..0000000 --- a/test/expected_dir/groovy1.groovy/groovy/code +++ /dev/null @@ -1,4 +0,0 @@ -println "hello, world" -for (arg in this.args ) { -println "Argument:" + arg; -} diff --git a/test/expected_dir/groovy1.groovy/groovy/comment b/test/expected_dir/groovy1.groovy/groovy/comment deleted file mode 100644 index a033d4b..0000000 --- a/test/expected_dir/groovy1.groovy/groovy/comment +++ /dev/null @@ -1,5 +0,0 @@ -//hello.groovy -// this is a comment -/* a block comment, commenting out an alternative to above: -this.args.each{ arg -> println "hello, ${arg}"} -*/ diff --git a/test/expected_dir/haml.haml b/test/expected_dir/haml.haml new file mode 100644 index 0000000..8613fde --- /dev/null +++ b/test/expected_dir/haml.haml @@ -0,0 +1,20 @@ +haml code %p +ruby code %p= "stuff" +haml comment / oneliner! +haml code %p +haml comment / +haml comment %p this won't render +haml comment %p it is a comment! +ruby code %p= "stuff" +haml code %p +ruby code - code +ruby code %p= "stuff" +haml code %p +haml blank +haml code \- not script! +haml comment -# silent comment +haml code %p +haml comment -# +haml comment silent +haml comment comment +haml code %br/ diff --git a/test/expected_dir/haml.haml/haml/blanks b/test/expected_dir/haml.haml/haml/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/haml.haml/haml/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/haml.haml/haml/code b/test/expected_dir/haml.haml/haml/code deleted file mode 100644 index 1c4e917..0000000 --- a/test/expected_dir/haml.haml/haml/code +++ /dev/null @@ -1,7 +0,0 @@ -%p -%p -%p -%p -\- not script! -%p -%br/ diff --git a/test/expected_dir/haml.haml/haml/comment b/test/expected_dir/haml.haml/haml/comment deleted file mode 100644 index 5d36be9..0000000 --- a/test/expected_dir/haml.haml/haml/comment +++ /dev/null @@ -1,8 +0,0 @@ -/ oneliner! -/ -%p this won't render -%p it is a comment! --# silent comment --# -silent -comment diff --git a/test/expected_dir/haml.haml/ruby/blanks b/test/expected_dir/haml.haml/ruby/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/haml.haml/ruby/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/haml.haml/ruby/code b/test/expected_dir/haml.haml/ruby/code deleted file mode 100644 index c3cb07e..0000000 --- a/test/expected_dir/haml.haml/ruby/code +++ /dev/null @@ -1,4 +0,0 @@ -%p= "stuff" -%p= "stuff" -- code -%p= "stuff" diff --git a/test/expected_dir/haskell1.hs b/test/expected_dir/haskell1.hs new file mode 100644 index 0000000..1f503ce --- /dev/null +++ b/test/expected_dir/haskell1.hs @@ -0,0 +1,108 @@ +haskell comment {-| +haskell comment This module contains some functions that are useful in several places in the +haskell comment program and don't belong to one specific other module. +haskell comment -} +haskell code module Gnutella.Misc where +haskell blank +haskell code import Data.ByteString(ByteString) +haskell code import qualified Data.ByteString as BS +haskell code import Data.Bits +haskell code import Data.Word +haskell code import Text.Read +haskell code import Data.Char(isNumber) +haskell code import Data.List(intersperse) +haskell code import Network +haskell code import Network.BSD(getHostByName, HostEntry(..)) +haskell code import Network.Socket(HostAddress(..)) +haskell code import Debug.Trace +haskell blank +haskell comment {-| +haskell comment Maakt van vier bytes een Word32. Gaat ervan uit dat die vier bytes little-endian achter elkaar +haskell comment staan. Als de gegeven string korter is dan 4 bytes, termineert de functie. Als de string langer +haskell comment is, worden alle bytes voorbij de vierde genegeerd. +haskell comment -} +haskell code composeWord32 :: ByteString -> Word32 +haskell code composeWord32 s = shiftL byte4 24 + shiftL byte3 16 + shiftL byte2 8 + byte1 +haskell code where byte1, byte2, byte3, byte4 :: Word32 +haskell code [byte1, byte2, byte3, byte4] = map fromIntegral $ BS.unpack (BS.take 4 s) +haskell blank +haskell comment {-| +haskell comment Turns a Word32 into a tuple of Word8s. The tuple is little-endian: the least +haskell comment significant octet comes first. +haskell comment -} +haskell code word32ToWord8s :: Word32 -> (Word8, Word8, Word8, Word8) +haskell code word32ToWord8s w = (fromIntegral (w .&. 0x000000ff) +haskell code ,fromIntegral (shiftR w 8 .&. 0x000000ff) +haskell code ,fromIntegral (shiftR w 16 .&. 0x000000ff) +haskell code ,fromIntegral (shiftR w 24 .&. 0x000000ff) +haskell code ) +haskell blank +haskell comment {-| +haskell comment Parses a host specification in the "name:12345"-style notation into a hostname +haskell comment and a port number. +haskell blank +haskell comment As a rather special feature, it returns 6346 as the port number when there is +haskell comment no port specified. When there is a port specified, but it is unparseable, it +haskell comment returns Nothing. +haskell comment -} +haskell code parseHostnameWithPort :: String -> IO (Maybe ((Word8, Word8, Word8, Word8) +haskell code ,PortNumber)) +haskell code parseHostnameWithPort str = do maybeHostName <- stringToIP hostNameStr +haskell code return $ (do portNum <- maybePortNum +haskell code hostName <- maybeHostName +haskell code return (hostName, portNum) +haskell code ) +haskell code where hostNameStr = takeWhile (/=':') str +haskell code maybePortNum = case tail (dropWhile (/=':') str) of +haskell code [] -> Just $ 6346 +haskell code s -> case reads s of +haskell code [] -> Nothing +haskell code (x:xs) -> Just $ fromIntegral $ fst x +haskell blank +haskell comment {-| +haskell comment Translates a string, representing an IP address, to a list of bytes. +haskell comment Returns Nothing when the string does not represent an IP address in xxx.xxx.xxx.xxx format +haskell comment -} +haskell code ipStringToBytes :: String -> Maybe (Word8, Word8, Word8, Word8) +haskell comment -- Again, hugs won't let us use regexes where they would be damn convenient +haskell code ipStringToBytes s = +haskell code let ipBytesStrings = splitAtDots s +haskell code in if all (all isNumber) ipBytesStrings +haskell code then let bytesList = map (fst . head . reads) ipBytesStrings +haskell code in Just (bytesList!!0 +haskell code ,bytesList!!1 +haskell code ,bytesList!!2 +haskell code ,bytesList!!3 +haskell code ) +haskell code else Nothing +haskell code where splitAtDots s = foldr (\c (n:nums) -> if c == '.' +haskell code then [] : n : nums +haskell code else (c:n) : nums +haskell code ) [[]] s +haskell blank +haskell comment {-| +haskell comment Translates a list of bytes representing an IP address (big endian) to a string +haskell comment in the xxx.xxx.xxx.xxx format. +haskell comment -} +haskell code ipBytesToString :: (Word8, Word8, Word8, Word8) -> String +haskell code ipBytesToString (b1, b2, b3, b4) = +haskell code concat $ intersperse "." $ map show [b1, b2, b3, b4] +haskell blank +haskell comment {-| +haskell comment Takes a String that's either an IP address or a hostname, and returns you the +haskell comment IP address as a list of 4 bytes (in big-endian byte order). It returns Nothing +haskell comment if there is no parse for the string as IP address and the hostname can't be +haskell comment found. +haskell comment -} +haskell code stringToIP :: String -> IO (Maybe (Word8, Word8, Word8, Word8)) +haskell code stringToIP hostName = case ipStringToBytes hostName of +haskell code Just a -> return (Just a) +haskell code Nothing -> do hostent <- getHostByName hostName +haskell code let ipWord32 = head (hostAddresses hostent) +haskell code ipWord8s = word32ToWord8s ipWord32 +haskell code return (Just ipWord8s) +haskell blank +haskell comment -- used in reading the hostcache +haskell code instance Read PortNumber where +haskell code readsPrec i = map (\(a, b) -> (fromIntegral a, b)) . (readsPrec i :: ReadS Word16) +haskell blank diff --git a/test/expected_dir/haskell1.hs/haskell/blanks b/test/expected_dir/haskell1.hs/haskell/blanks deleted file mode 100644 index 9a03714..0000000 --- a/test/expected_dir/haskell1.hs/haskell/blanks +++ /dev/null @@ -1 +0,0 @@ -10 \ No newline at end of file diff --git a/test/expected_dir/haskell1.hs/haskell/code b/test/expected_dir/haskell1.hs/haskell/code deleted file mode 100644 index d589023..0000000 --- a/test/expected_dir/haskell1.hs/haskell/code +++ /dev/null @@ -1,62 +0,0 @@ -module Gnutella.Misc where -import Data.ByteString(ByteString) -import qualified Data.ByteString as BS -import Data.Bits -import Data.Word -import Text.Read -import Data.Char(isNumber) -import Data.List(intersperse) -import Network -import Network.BSD(getHostByName, HostEntry(..)) -import Network.Socket(HostAddress(..)) -import Debug.Trace -composeWord32 :: ByteString -> Word32 -composeWord32 s = shiftL byte4 24 + shiftL byte3 16 + shiftL byte2 8 + byte1 -where byte1, byte2, byte3, byte4 :: Word32 -[byte1, byte2, byte3, byte4] = map fromIntegral $ BS.unpack (BS.take 4 s) -word32ToWord8s :: Word32 -> (Word8, Word8, Word8, Word8) -word32ToWord8s w = (fromIntegral (w .&. 0x000000ff) -,fromIntegral (shiftR w 8 .&. 0x000000ff) -,fromIntegral (shiftR w 16 .&. 0x000000ff) -,fromIntegral (shiftR w 24 .&. 0x000000ff) -) -parseHostnameWithPort :: String -> IO (Maybe ((Word8, Word8, Word8, Word8) -,PortNumber)) -parseHostnameWithPort str = do maybeHostName <- stringToIP hostNameStr -return $ (do portNum <- maybePortNum -hostName <- maybeHostName -return (hostName, portNum) -) -where hostNameStr = takeWhile (/=':') str -maybePortNum = case tail (dropWhile (/=':') str) of -[] -> Just $ 6346 -s -> case reads s of -[] -> Nothing -(x:xs) -> Just $ fromIntegral $ fst x -ipStringToBytes :: String -> Maybe (Word8, Word8, Word8, Word8) -ipStringToBytes s = -let ipBytesStrings = splitAtDots s -in if all (all isNumber) ipBytesStrings -then let bytesList = map (fst . head . reads) ipBytesStrings -in Just (bytesList!!0 -,bytesList!!1 -,bytesList!!2 -,bytesList!!3 -) -else Nothing -where splitAtDots s = foldr (\c (n:nums) -> if c == '.' -then [] : n : nums -else (c:n) : nums -) [[]] s -ipBytesToString :: (Word8, Word8, Word8, Word8) -> String -ipBytesToString (b1, b2, b3, b4) = -concat $ intersperse "." $ map show [b1, b2, b3, b4] -stringToIP :: String -> IO (Maybe (Word8, Word8, Word8, Word8)) -stringToIP hostName = case ipStringToBytes hostName of -Just a -> return (Just a) -Nothing -> do hostent <- getHostByName hostName -let ipWord32 = head (hostAddresses hostent) -ipWord8s = word32ToWord8s ipWord32 -return (Just ipWord8s) -instance Read PortNumber where -readsPrec i = map (\(a, b) -> (fromIntegral a, b)) . (readsPrec i :: ReadS Word16) diff --git a/test/expected_dir/haskell1.hs/haskell/comment b/test/expected_dir/haskell1.hs/haskell/comment deleted file mode 100644 index 497490f..0000000 --- a/test/expected_dir/haskell1.hs/haskell/comment +++ /dev/null @@ -1,36 +0,0 @@ -{-| -This module contains some functions that are useful in several places in the -program and don't belong to one specific other module. --} -{-| -Maakt van vier bytes een Word32. Gaat ervan uit dat die vier bytes little-endian achter elkaar -staan. Als de gegeven string korter is dan 4 bytes, termineert de functie. Als de string langer -is, worden alle bytes voorbij de vierde genegeerd. --} -{-| -Turns a Word32 into a tuple of Word8s. The tuple is little-endian: the least -significant octet comes first. --} -{-| -Parses a host specification in the "name:12345"-style notation into a hostname -and a port number. -As a rather special feature, it returns 6346 as the port number when there is -no port specified. When there is a port specified, but it is unparseable, it -returns Nothing. --} -{-| -Translates a string, representing an IP address, to a list of bytes. -Returns Nothing when the string does not represent an IP address in xxx.xxx.xxx.xxx format --} --- Again, hugs won't let us use regexes where they would be damn convenient -{-| -Translates a list of bytes representing an IP address (big endian) to a string -in the xxx.xxx.xxx.xxx format. --} -{-| -Takes a String that's either an IP address or a hostname, and returns you the -IP address as a list of 4 bytes (in big-endian byte order). It returns Nothing -if there is no parse for the string as IP address and the hostname can't be -found. --} --- used in reading the hostcache diff --git a/test/expected_dir/haskell2.hs b/test/expected_dir/haskell2.hs new file mode 100644 index 0000000..80b3dfc --- /dev/null +++ b/test/expected_dir/haskell2.hs @@ -0,0 +1,4 @@ +haskell comment {-| +haskell blank +haskell comment -} +haskell blank diff --git a/test/expected_dir/haskell2.hs/haskell/blanks b/test/expected_dir/haskell2.hs/haskell/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/haskell2.hs/haskell/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/haskell2.hs/haskell/comment b/test/expected_dir/haskell2.hs/haskell/comment deleted file mode 100644 index f1158de..0000000 --- a/test/expected_dir/haskell2.hs/haskell/comment +++ /dev/null @@ -1,2 +0,0 @@ -{-| --} diff --git a/test/expected_dir/haskell3.hs b/test/expected_dir/haskell3.hs new file mode 100644 index 0000000..8d2c542 --- /dev/null +++ b/test/expected_dir/haskell3.hs @@ -0,0 +1,5 @@ +haskell comment {- +haskell comment {- 3 lines of comments total! -} +haskell blank +haskell comment -} +haskell blank diff --git a/test/expected_dir/haskell3.hs/haskell/blanks b/test/expected_dir/haskell3.hs/haskell/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/haskell3.hs/haskell/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/haskell3.hs/haskell/comment b/test/expected_dir/haskell3.hs/haskell/comment deleted file mode 100644 index 3f50acf..0000000 --- a/test/expected_dir/haskell3.hs/haskell/comment +++ /dev/null @@ -1,3 +0,0 @@ -{- -{- 3 lines of comments total! -} --} diff --git a/test/expected_dir/haxe1.hx b/test/expected_dir/haxe1.hx new file mode 100644 index 0000000..f4551b2 --- /dev/null +++ b/test/expected_dir/haxe1.hx @@ -0,0 +1,101 @@ +haxe comment /* +haxe comment # ***** BEGIN LICENSE BLOCK ***** +haxe comment Copyright the original author or authors. +haxe comment Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); +haxe comment you may not use this file except in compliance with the License. +haxe comment You may obtain a copy of the License at +haxe comment http://www.mozilla.org/MPL/MPL-1.1.html +haxe comment Unless required by applicable law or agreed to in writing, software +haxe comment distributed under the License is distributed on an "AS IS" BASIS, +haxe comment WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +haxe comment See the License for the specific language governing permissions and +haxe comment limitations under the License. +haxe blank +haxe comment # ***** END LICENSE BLOCK ***** +haxe comment */ +haxe blank +haxe code package sandy.parser; +haxe blank +haxe comment /** +haxe comment * The Parser factory class creates instances of parser classes. +haxe comment * The specific parser can be specified in the create method's second parameter. +haxe comment * +haxe comment * @author Thomas Pfeiffer - kiroukou +haxe comment * @author Niel Drummond - haXe port +haxe comment * +haxe comment * +haxe comment * +haxe comment * @example To parse a 3DS file at runtime: +haxe comment * +haxe comment * +haxe comment * var parser:IParser = Parser.create( "/path/to/my/3dsfile.3ds", Parser.max ); +haxe comment * +haxe comment * +haxe comment */ +haxe blank +haxe code class Parser +haxe code { +haxe comment /** +haxe comment * Parameter that is used to specify that the ASE (ASCII Scene Export) +haxe comment * Parser should be used +haxe comment */ +haxe code public static var ASE:String = "ASE"; +haxe comment /** +haxe comment * Parameter that is used to specify that the 3DS (3D Studio) Parser +haxe comment * should be used +haxe comment */ +haxe code public static var MAX_3DS:String = "3DS"; +haxe comment /** +haxe comment * Parameter that is used to specify that the COLLADA (COLLAborative +haxe comment * Design Activity ) Parser should be used +haxe comment */ +haxe code public static var COLLADA:String = "DAE"; +haxe blank +haxe comment /** +haxe comment * The create method chooses which parser to use. This can be done automatically +haxe comment * by looking at the file extension or by passing the parser type String as the +haxe comment * second parameter. +haxe comment * +haxe comment * @example To parse a 3DS file at runtime: +haxe comment * +haxe comment * +haxe comment * var parser:IParser = Parser.create( "/path/to/my/3dsfile.3ds", Parser.MAX ); +haxe comment * +haxe comment * +haxe comment * @param p_sFile Can be either a string pointing to the location of the +haxe comment * file or an instance of an embedded file +haxe comment * @param p_sParserType The parser type string +haxe comment * @param p_nScale The scale factor +haxe comment * @return The parser to be used +haxe comment */ +haxe code public static function create( p_sFile:Dynamic, ?p_sParserType:String, ?p_nScale:Float ):IParser +haxe code { +haxe code if ( p_nScale == null ) p_nScale = 1; +haxe blank +haxe code var l_sExt:String,l_iParser:IParser = null; +haxe comment // -- +haxe code if( Std.is( p_sFile, String ) && p_sParserType == null ) +haxe code { +haxe code l_sExt = (p_sFile.split('.')).reverse()[0]; +haxe code } +haxe code else +haxe code { +haxe code l_sExt = p_sParserType; +haxe code } +haxe comment // -- +haxe code switch( l_sExt.toUpperCase() ) +haxe code { +haxe code case "ASE": +haxe code l_iParser = new ASEParser( p_sFile, p_nScale ); +haxe code case "OBJ": +haxe code case "DAE": +haxe code l_iParser = new ColladaParser( p_sFile, p_nScale ); +haxe code case "3DS": +haxe code l_iParser = new Parser3DS( p_sFile, p_nScale ); +haxe code default: +haxe code } +haxe comment // -- +haxe code return l_iParser; +haxe code } +haxe code } +haxe blank diff --git a/test/expected_dir/html1.html b/test/expected_dir/html1.html new file mode 100644 index 0000000..29032bf --- /dev/null +++ b/test/expected_dir/html1.html @@ -0,0 +1,38 @@ +html code +html code +html code +html code foo +html code +html code +html code +html code +html code

+html code +html code not in comment +html code +html code italic?]]> +html code

+html comment +html code +html code diff --git a/test/expected_dir/html1.html/css/blanks b/test/expected_dir/html1.html/css/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/html1.html/css/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/html1.html/css/code b/test/expected_dir/html1.html/css/code deleted file mode 100644 index 014b64e..0000000 --- a/test/expected_dir/html1.html/css/code +++ /dev/null @@ -1,3 +0,0 @@ -p { -color: #444 -} diff --git a/test/expected_dir/html1.html/html/blanks b/test/expected_dir/html1.html/html/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/html1.html/html/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/html1.html/html/code b/test/expected_dir/html1.html/html/code deleted file mode 100644 index b5eca21..0000000 --- a/test/expected_dir/html1.html/html/code +++ /dev/null @@ -1,18 +0,0 @@ - - - -foo - - - - -

- -not in comment - -italic?]]> -

- - diff --git a/test/expected_dir/html1.html/html/comment b/test/expected_dir/html1.html/html/comment deleted file mode 100644 index 30c82f6..0000000 --- a/test/expected_dir/html1.html/html/comment +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/expected_dir/html1.html/javascript/blanks b/test/expected_dir/html1.html/javascript/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/html1.html/javascript/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/html1.html/javascript/code b/test/expected_dir/html1.html/javascript/code deleted file mode 100644 index 69671f1..0000000 --- a/test/expected_dir/html1.html/javascript/code +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/test/expected_dir/html1.html/javascript/comment b/test/expected_dir/html1.html/javascript/comment deleted file mode 100644 index ecd132d..0000000 --- a/test/expected_dir/html1.html/javascript/comment +++ /dev/null @@ -1 +0,0 @@ -// javascript comment diff --git a/test/expected_dir/idl_pvwave.pro b/test/expected_dir/idl_pvwave.pro new file mode 100644 index 0000000..c3fad2b --- /dev/null +++ b/test/expected_dir/idl_pvwave.pro @@ -0,0 +1,83 @@ +idl_pvwave comment ;+ +idl_pvwave comment ; NAME: +idl_pvwave comment ; SHOWFONT +idl_pvwave comment ; +idl_pvwave comment ; PURPOSE: +idl_pvwave comment ; Uses current graphics device to draw a map of characters +idl_pvwave comment ; available in the font specified in argument +idl_pvwave comment ; +idl_pvwave comment ; CATEGORY: +idl_pvwave comment ; General +idl_pvwave comment ; +idl_pvwave comment ; CALLING SEQUENCE: +idl_pvwave comment ; showfont, num, 'title' ; table of font num entitled 'title' +idl_pvwave comment ; +idl_pvwave comment ; KEYWORD PARAMETERS: +idl_pvwave comment ; /encapsulated ; ignored (just for compatibility) +idl_pvwave comment ; /tt_font ; ignored (just for compatibility) +idl_pvwave comment ; base = 16 ; number of columns in the table +idl_pvwave comment ; beg = 32 ; first character +idl_pvwave comment ; fin = num eq 3 ? 255 : 127 ; last character +idl_pvwave comment ; +idl_pvwave comment ; OUTPUTS: +idl_pvwave comment ; None. +idl_pvwave comment ; +idl_pvwave comment ; OPTIONAL OUTPUTS: +idl_pvwave comment ; None. +idl_pvwave comment ; +idl_pvwave comment ; COMMON BLOCKS: +idl_pvwave comment ; None. +idl_pvwave comment ; +idl_pvwave comment ; SIDE EFFECTS: +idl_pvwave comment ; Draws a font table on the current graphic device. +idl_pvwave comment ; +idl_pvwave comment ; RESTRICTIONS: +idl_pvwave comment ; None. +idl_pvwave comment ; +idl_pvwave comment ; PROCEDURE: +idl_pvwave comment ; +idl_pvwave comment ; EXAMPLE: +idl_pvwave comment ; showfont, 9, 'GDL math symbols' ; show mappings for font 9 +idl_pvwave comment ; +idl_pvwave comment ; MODIFICATION HISTORY: +idl_pvwave comment ; Written by: Sylwester Arabas (2008/12/28) +idl_pvwave comment ;- +idl_pvwave comment ; LICENCE: +idl_pvwave comment ; Copyright (C) 2008, +idl_pvwave comment ; This program is free software; you can redistribute it and/or modify +idl_pvwave comment ; it under the terms of the GNU General Public License as published by +idl_pvwave comment ; the Free Software Foundation; either version 2 of the License, or +idl_pvwave comment ; (at your option) any later version. +idl_pvwave comment ;- +idl_pvwave blank +idl_pvwave code pro showfont, num, name, encapsulated=eps, tt_font=tt, base=base, beg=beg, fin=fin +idl_pvwave blank +idl_pvwave comment ; handling default keyword values +idl_pvwave code if not keyword_set(base) then base = 16 +idl_pvwave code if not keyword_set(beg) then beg = 32 +idl_pvwave code if not keyword_set(fin) then fin = num eq 3 ? 255 : 127 +idl_pvwave code if not keyword_set(name) then name = '' +idl_pvwave blank +idl_pvwave comment ; constructing horizontal and vertical grid lines +idl_pvwave code n_hor = (fin + 1 - beg) / base + 1 +idl_pvwave code h_x = (double(rebin(base * byte(128 * indgen(2 * (n_hor))) / 128, 4 * n_hor, /sample)))[1:4 * n_hor - 1] - .5 +idl_pvwave code h_y = (double(rebin(beg + indgen(n_hor) * base, 4 * n_hor, /sample)))[0:4 * n_hor - 2] - base/2. +idl_pvwave code v_x = base - indgen(4 * base - 1) / 4 - .5 +idl_pvwave code v_y = (double(rebin(byte(128 * indgen(2 * (base))) / 128, 4 * base, /sample)))[1:4 * base - 1] $ +idl_pvwave code * base * ((fin + 1 - beg) / base) + beg - base / 2. +idl_pvwave blank +idl_pvwave comment ; ploting grid and title +idl_pvwave code plot, [h_x, v_x], [h_y, v_y], $ +idl_pvwave code title='Font ' + strtrim(string(num), 2) + ', ' + name, $ +idl_pvwave code xrange=[-1, base], $ +idl_pvwave code yrange=[base * ((fin + 1) / base), beg - base], $ +idl_pvwave code yticks=n_hor, $ +idl_pvwave code xticks=base+1, $ +idl_pvwave code xtitle='char mod ' + strtrim(string(base), 2), $ +idl_pvwave code ytitle=strtrim(string(base), 2) + ' * (char / ' + strtrim(string(base), 2) + ')' +idl_pvwave blank +idl_pvwave comment ; ploting characters +idl_pvwave code for c = beg, fin do $ +idl_pvwave code xyouts, (c mod base), base * (c / base), '!' + strtrim(string(num), 2) + string(byte(c)) +idl_pvwave blank +idl_pvwave code end diff --git a/test/expected_dir/java1.java b/test/expected_dir/java1.java new file mode 100644 index 0000000..77a4c28 --- /dev/null +++ b/test/expected_dir/java1.java @@ -0,0 +1,48 @@ +java comment // Program 11.6: A nicer sine wave +java code import java.applet.Applet; +java code import java.awt.Graphics; +java blank +java code public class SineApplet2 extends Applet { +java blank +java code public void paint(Graphics g) { +java blank +java code int i, j1, j2; +java blank +java code j1 = yvalue(0); +java code for (i = 0; i < size().width; i++) { +java code j2 = yvalue(i+1); +java code g.drawLine(i, j1 ,i+1, j2); +java code j1 = j2; +java code } +java blank +java code } +java blank +java comment // Given the xpoint we're given calculate the Cartesian equivalent +java code private int yvalue(int ivalue) { +java blank +java code double xmin = -10.0; +java code double xmax = 10.0; +java code double ymin = -1.0; +java code double ymax = 1.0; +java code double x, y; +java code int jvalue; +java blank +java code x = (ivalue * (xmax - xmin)/(size().width - 1)) + xmin; +java blank +java comment // Take the sine of that x +java code y = Math.sin(x); +java blank +java comment // Scale y into window coordinates +java code jvalue = (int) ((y - ymin)*(size().height - 1)/ +java code (ymax - ymin)); +java blank +java comment /* Switch jvalue from Cartesian coordinates +java comment to computer graphics coordinates */ +java code jvalue = size().height - jvalue; +java blank +java code return jvalue; +java blank +java code } +java blank +java code } +java blank diff --git a/test/expected_dir/java1.java/java/blanks b/test/expected_dir/java1.java/java/blanks deleted file mode 100644 index 3f10ffe..0000000 --- a/test/expected_dir/java1.java/java/blanks +++ /dev/null @@ -1 +0,0 @@ -15 \ No newline at end of file diff --git a/test/expected_dir/java1.java/java/code b/test/expected_dir/java1.java/java/code deleted file mode 100644 index 5966c9a..0000000 --- a/test/expected_dir/java1.java/java/code +++ /dev/null @@ -1,27 +0,0 @@ -import java.applet.Applet; -import java.awt.Graphics; -public class SineApplet2 extends Applet { -public void paint(Graphics g) { -int i, j1, j2; -j1 = yvalue(0); -for (i = 0; i < size().width; i++) { -j2 = yvalue(i+1); -g.drawLine(i, j1 ,i+1, j2); -j1 = j2; -} -} -private int yvalue(int ivalue) { -double xmin = -10.0; -double xmax = 10.0; -double ymin = -1.0; -double ymax = 1.0; -double x, y; -int jvalue; -x = (ivalue * (xmax - xmin)/(size().width - 1)) + xmin; -y = Math.sin(x); -jvalue = (int) ((y - ymin)*(size().height - 1)/ -(ymax - ymin)); -jvalue = size().height - jvalue; -return jvalue; -} -} diff --git a/test/expected_dir/java1.java/java/comment b/test/expected_dir/java1.java/java/comment deleted file mode 100644 index b628454..0000000 --- a/test/expected_dir/java1.java/java/comment +++ /dev/null @@ -1,6 +0,0 @@ -// Program 11.6: A nicer sine wave -// Given the xpoint we're given calculate the Cartesian equivalent -// Take the sine of that x -// Scale y into window coordinates -/* Switch jvalue from Cartesian coordinates -to computer graphics coordinates */ diff --git a/test/expected_dir/java2.java b/test/expected_dir/java2.java new file mode 100644 index 0000000..bf64cae --- /dev/null +++ b/test/expected_dir/java2.java @@ -0,0 +1,3 @@ +java comment /** +java comment */ +java blank diff --git a/test/expected_dir/java2.java/java/blanks b/test/expected_dir/java2.java/java/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/java2.java/java/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/java2.java/java/comment b/test/expected_dir/java2.java/java/comment deleted file mode 100644 index b3e6072..0000000 --- a/test/expected_dir/java2.java/java/comment +++ /dev/null @@ -1,2 +0,0 @@ -/** -*/ diff --git a/test/expected_dir/js1.js b/test/expected_dir/js1.js new file mode 100644 index 0000000..f7dabcb --- /dev/null +++ b/test/expected_dir/js1.js @@ -0,0 +1,1781 @@ +javascript comment /* Prototype JavaScript framework, version 1.4.0 +javascript comment * (c) 2005 Sam Stephenson +javascript comment * +javascript comment * Prototype is freely distributable under the terms of an MIT-style license. +javascript comment * For details, see the Prototype web site: http://prototype.conio.net/ +javascript comment * +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code var Prototype = { +javascript code Version: '1.4.0', +javascript code ScriptFragment: '(?:)((\n|\r|.)*?)(?:<\/script>)', +javascript blank +javascript code emptyFunction: function() {}, +javascript code K: function(x) {return x} +javascript code } +javascript blank +javascript code var Class = { +javascript code create: function() { +javascript code return function() { +javascript code this.initialize.apply(this, arguments); +javascript code } +javascript code } +javascript code } +javascript blank +javascript code var Abstract = new Object(); +javascript blank +javascript code Object.extend = function(destination, source) { +javascript code for (property in source) { +javascript code destination[property] = source[property]; +javascript code } +javascript code return destination; +javascript code } +javascript blank +javascript code Object.inspect = function(object) { +javascript code try { +javascript code if (object == undefined) return 'undefined'; +javascript code if (object == null) return 'null'; +javascript code return object.inspect ? object.inspect() : object.toString(); +javascript code } catch (e) { +javascript code if (e instanceof RangeError) return '...'; +javascript code throw e; +javascript code } +javascript code } +javascript blank +javascript code Function.prototype.bind = function() { +javascript code var __method = this, args = $A(arguments), object = args.shift(); +javascript code return function() { +javascript code return __method.apply(object, args.concat($A(arguments))); +javascript code } +javascript code } +javascript blank +javascript code Function.prototype.bindAsEventListener = function(object) { +javascript code var __method = this; +javascript code return function(event) { +javascript code return __method.call(object, event || window.event); +javascript code } +javascript code } +javascript blank +javascript code Object.extend(Number.prototype, { +javascript code toColorPart: function() { +javascript code var digits = this.toString(16); +javascript code if (this < 16) return '0' + digits; +javascript code return digits; +javascript code }, +javascript blank +javascript code succ: function() { +javascript code return this + 1; +javascript code }, +javascript blank +javascript code times: function(iterator) { +javascript code $R(0, this, true).each(iterator); +javascript code return this; +javascript code } +javascript code }); +javascript blank +javascript code var Try = { +javascript code these: function() { +javascript code var returnValue; +javascript blank +javascript code for (var i = 0; i < arguments.length; i++) { +javascript code var lambda = arguments[i]; +javascript code try { +javascript code returnValue = lambda(); +javascript code break; +javascript code } catch (e) {} +javascript code } +javascript blank +javascript code return returnValue; +javascript code } +javascript code } +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code var PeriodicalExecuter = Class.create(); +javascript code PeriodicalExecuter.prototype = { +javascript code initialize: function(callback, frequency) { +javascript code this.callback = callback; +javascript code this.frequency = frequency; +javascript code this.currentlyExecuting = false; +javascript blank +javascript code this.registerCallback(); +javascript code }, +javascript blank +javascript code registerCallback: function() { +javascript code setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); +javascript code }, +javascript blank +javascript code onTimerEvent: function() { +javascript code if (!this.currentlyExecuting) { +javascript code try { +javascript code this.currentlyExecuting = true; +javascript code this.callback(); +javascript code } finally { +javascript code this.currentlyExecuting = false; +javascript code } +javascript code } +javascript code } +javascript code } +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code function $() { +javascript code var elements = new Array(); +javascript blank +javascript code for (var i = 0; i < arguments.length; i++) { +javascript code var element = arguments[i]; +javascript code if (typeof element == 'string') +javascript code element = document.getElementById(element); +javascript blank +javascript code if (arguments.length == 1) +javascript code return element; +javascript blank +javascript code elements.push(element); +javascript code } +javascript blank +javascript code return elements; +javascript code } +javascript code Object.extend(String.prototype, { +javascript code stripTags: function() { +javascript code return this.replace(/<\/?[^>]+>/gi, ''); +javascript code }, +javascript blank +javascript code stripScripts: function() { +javascript code return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); +javascript code }, +javascript blank +javascript code extractScripts: function() { +javascript code var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); +javascript code var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); +javascript code return (this.match(matchAll) || []).map(function(scriptTag) { +javascript code return (scriptTag.match(matchOne) || ['', ''])[1]; +javascript code }); +javascript code }, +javascript blank +javascript code evalScripts: function() { +javascript code return this.extractScripts().map(eval); +javascript code }, +javascript blank +javascript code escapeHTML: function() { +javascript code var div = document.createElement('div'); +javascript code var text = document.createTextNode(this); +javascript code div.appendChild(text); +javascript code return div.innerHTML; +javascript code }, +javascript blank +javascript code unescapeHTML: function() { +javascript code var div = document.createElement('div'); +javascript code div.innerHTML = this.stripTags(); +javascript code return div.childNodes[0] ? div.childNodes[0].nodeValue : ''; +javascript code }, +javascript blank +javascript code toQueryParams: function() { +javascript code var pairs = this.match(/^\??(.*)$/)[1].split('&'); +javascript code return pairs.inject({}, function(params, pairString) { +javascript code var pair = pairString.split('='); +javascript code params[pair[0]] = pair[1]; +javascript code return params; +javascript code }); +javascript code }, +javascript blank +javascript code toArray: function() { +javascript code return this.split(''); +javascript code }, +javascript blank +javascript code camelize: function() { +javascript code var oStringList = this.split('-'); +javascript code if (oStringList.length == 1) return oStringList[0]; +javascript blank +javascript code var camelizedString = this.indexOf('-') == 0 +javascript code ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) +javascript code : oStringList[0]; +javascript blank +javascript code for (var i = 1, len = oStringList.length; i < len; i++) { +javascript code var s = oStringList[i]; +javascript code camelizedString += s.charAt(0).toUpperCase() + s.substring(1); +javascript code } +javascript blank +javascript code return camelizedString; +javascript code }, +javascript blank +javascript code inspect: function() { +javascript code return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'"; +javascript code } +javascript code }); +javascript blank +javascript code String.prototype.parseQuery = String.prototype.toQueryParams; +javascript blank +javascript code var $break = new Object(); +javascript code var $continue = new Object(); +javascript blank +javascript code var Enumerable = { +javascript code each: function(iterator) { +javascript code var index = 0; +javascript code try { +javascript code this._each(function(value) { +javascript code try { +javascript code iterator(value, index++); +javascript code } catch (e) { +javascript code if (e != $continue) throw e; +javascript code } +javascript code }); +javascript code } catch (e) { +javascript code if (e != $break) throw e; +javascript code } +javascript code }, +javascript blank +javascript code all: function(iterator) { +javascript code var result = true; +javascript code this.each(function(value, index) { +javascript code result = result && !!(iterator || Prototype.K)(value, index); +javascript code if (!result) throw $break; +javascript code }); +javascript code return result; +javascript code }, +javascript blank +javascript code any: function(iterator) { +javascript code var result = true; +javascript code this.each(function(value, index) { +javascript code if (result = !!(iterator || Prototype.K)(value, index)) +javascript code throw $break; +javascript code }); +javascript code return result; +javascript code }, +javascript blank +javascript code collect: function(iterator) { +javascript code var results = []; +javascript code this.each(function(value, index) { +javascript code results.push(iterator(value, index)); +javascript code }); +javascript code return results; +javascript code }, +javascript blank +javascript code detect: function (iterator) { +javascript code var result; +javascript code this.each(function(value, index) { +javascript code if (iterator(value, index)) { +javascript code result = value; +javascript code throw $break; +javascript code } +javascript code }); +javascript code return result; +javascript code }, +javascript blank +javascript code findAll: function(iterator) { +javascript code var results = []; +javascript code this.each(function(value, index) { +javascript code if (iterator(value, index)) +javascript code results.push(value); +javascript code }); +javascript code return results; +javascript code }, +javascript blank +javascript code grep: function(pattern, iterator) { +javascript code var results = []; +javascript code this.each(function(value, index) { +javascript code var stringValue = value.toString(); +javascript code if (stringValue.match(pattern)) +javascript code results.push((iterator || Prototype.K)(value, index)); +javascript code }) +javascript code return results; +javascript code }, +javascript blank +javascript code include: function(object) { +javascript code var found = false; +javascript code this.each(function(value) { +javascript code if (value == object) { +javascript code found = true; +javascript code throw $break; +javascript code } +javascript code }); +javascript code return found; +javascript code }, +javascript blank +javascript code inject: function(memo, iterator) { +javascript code this.each(function(value, index) { +javascript code memo = iterator(memo, value, index); +javascript code }); +javascript code return memo; +javascript code }, +javascript blank +javascript code invoke: function(method) { +javascript code var args = $A(arguments).slice(1); +javascript code return this.collect(function(value) { +javascript code return value[method].apply(value, args); +javascript code }); +javascript code }, +javascript blank +javascript code max: function(iterator) { +javascript code var result; +javascript code this.each(function(value, index) { +javascript code value = (iterator || Prototype.K)(value, index); +javascript code if (value >= (result || value)) +javascript code result = value; +javascript code }); +javascript code return result; +javascript code }, +javascript blank +javascript code min: function(iterator) { +javascript code var result; +javascript code this.each(function(value, index) { +javascript code value = (iterator || Prototype.K)(value, index); +javascript code if (value <= (result || value)) +javascript code result = value; +javascript code }); +javascript code return result; +javascript code }, +javascript blank +javascript code partition: function(iterator) { +javascript code var trues = [], falses = []; +javascript code this.each(function(value, index) { +javascript code ((iterator || Prototype.K)(value, index) ? +javascript code trues : falses).push(value); +javascript code }); +javascript code return [trues, falses]; +javascript code }, +javascript blank +javascript code pluck: function(property) { +javascript code var results = []; +javascript code this.each(function(value, index) { +javascript code results.push(value[property]); +javascript code }); +javascript code return results; +javascript code }, +javascript blank +javascript code reject: function(iterator) { +javascript code var results = []; +javascript code this.each(function(value, index) { +javascript code if (!iterator(value, index)) +javascript code results.push(value); +javascript code }); +javascript code return results; +javascript code }, +javascript blank +javascript code sortBy: function(iterator) { +javascript code return this.collect(function(value, index) { +javascript code return {value: value, criteria: iterator(value, index)}; +javascript code }).sort(function(left, right) { +javascript code var a = left.criteria, b = right.criteria; +javascript code return a < b ? -1 : a > b ? 1 : 0; +javascript code }).pluck('value'); +javascript code }, +javascript blank +javascript code toArray: function() { +javascript code return this.collect(Prototype.K); +javascript code }, +javascript blank +javascript code zip: function() { +javascript code var iterator = Prototype.K, args = $A(arguments); +javascript code if (typeof args.last() == 'function') +javascript code iterator = args.pop(); +javascript blank +javascript code var collections = [this].concat(args).map($A); +javascript code return this.map(function(value, index) { +javascript code iterator(value = collections.pluck(index)); +javascript code return value; +javascript code }); +javascript code }, +javascript blank +javascript code inspect: function() { +javascript code return '#'; +javascript code } +javascript code } +javascript blank +javascript code Object.extend(Enumerable, { +javascript code map: Enumerable.collect, +javascript code find: Enumerable.detect, +javascript code select: Enumerable.findAll, +javascript code member: Enumerable.include, +javascript code entries: Enumerable.toArray +javascript code }); +javascript code var $A = Array.from = function(iterable) { +javascript code if (!iterable) return []; +javascript code if (iterable.toArray) { +javascript code return iterable.toArray(); +javascript code } else { +javascript code var results = []; +javascript code for (var i = 0; i < iterable.length; i++) +javascript code results.push(iterable[i]); +javascript code return results; +javascript code } +javascript code } +javascript blank +javascript code Object.extend(Array.prototype, Enumerable); +javascript blank +javascript code Array.prototype._reverse = Array.prototype.reverse; +javascript blank +javascript code Object.extend(Array.prototype, { +javascript code _each: function(iterator) { +javascript code for (var i = 0; i < this.length; i++) +javascript code iterator(this[i]); +javascript code }, +javascript blank +javascript code clear: function() { +javascript code this.length = 0; +javascript code return this; +javascript code }, +javascript blank +javascript code first: function() { +javascript code return this[0]; +javascript code }, +javascript blank +javascript code last: function() { +javascript code return this[this.length - 1]; +javascript code }, +javascript blank +javascript code compact: function() { +javascript code return this.select(function(value) { +javascript code return value != undefined || value != null; +javascript code }); +javascript code }, +javascript blank +javascript code flatten: function() { +javascript code return this.inject([], function(array, value) { +javascript code return array.concat(value.constructor == Array ? +javascript code value.flatten() : [value]); +javascript code }); +javascript code }, +javascript blank +javascript code without: function() { +javascript code var values = $A(arguments); +javascript code return this.select(function(value) { +javascript code return !values.include(value); +javascript code }); +javascript code }, +javascript blank +javascript code indexOf: function(object) { +javascript code for (var i = 0; i < this.length; i++) +javascript code if (this[i] == object) return i; +javascript code return -1; +javascript code }, +javascript blank +javascript code reverse: function(inline) { +javascript code return (inline !== false ? this : this.toArray())._reverse(); +javascript code }, +javascript blank +javascript code shift: function() { +javascript code var result = this[0]; +javascript code for (var i = 0; i < this.length - 1; i++) +javascript code this[i] = this[i + 1]; +javascript code this.length--; +javascript code return result; +javascript code }, +javascript blank +javascript code inspect: function() { +javascript code return '[' + this.map(Object.inspect).join(', ') + ']'; +javascript code } +javascript code }); +javascript code var Hash = { +javascript code _each: function(iterator) { +javascript code for (key in this) { +javascript code var value = this[key]; +javascript code if (typeof value == 'function') continue; +javascript blank +javascript code var pair = [key, value]; +javascript code pair.key = key; +javascript code pair.value = value; +javascript code iterator(pair); +javascript code } +javascript code }, +javascript blank +javascript code keys: function() { +javascript code return this.pluck('key'); +javascript code }, +javascript blank +javascript code values: function() { +javascript code return this.pluck('value'); +javascript code }, +javascript blank +javascript code merge: function(hash) { +javascript code return $H(hash).inject($H(this), function(mergedHash, pair) { +javascript code mergedHash[pair.key] = pair.value; +javascript code return mergedHash; +javascript code }); +javascript code }, +javascript blank +javascript code toQueryString: function() { +javascript code return this.map(function(pair) { +javascript code return pair.map(encodeURIComponent).join('='); +javascript code }).join('&'); +javascript code }, +javascript blank +javascript code inspect: function() { +javascript code return '#'; +javascript code } +javascript code } +javascript blank +javascript code function $H(object) { +javascript code var hash = Object.extend({}, object || {}); +javascript code Object.extend(hash, Enumerable); +javascript code Object.extend(hash, Hash); +javascript code return hash; +javascript code } +javascript code ObjectRange = Class.create(); +javascript code Object.extend(ObjectRange.prototype, Enumerable); +javascript code Object.extend(ObjectRange.prototype, { +javascript code initialize: function(start, end, exclusive) { +javascript code this.start = start; +javascript code this.end = end; +javascript code this.exclusive = exclusive; +javascript code }, +javascript blank +javascript code _each: function(iterator) { +javascript code var value = this.start; +javascript code do { +javascript code iterator(value); +javascript code value = value.succ(); +javascript code } while (this.include(value)); +javascript code }, +javascript blank +javascript code include: function(value) { +javascript code if (value < this.start) +javascript code return false; +javascript code if (this.exclusive) +javascript code return value < this.end; +javascript code return value <= this.end; +javascript code } +javascript code }); +javascript blank +javascript code var $R = function(start, end, exclusive) { +javascript code return new ObjectRange(start, end, exclusive); +javascript code } +javascript blank +javascript code var Ajax = { +javascript code getTransport: function() { +javascript code return Try.these( +javascript code function() {return new ActiveXObject('Msxml2.XMLHTTP')}, +javascript code function() {return new ActiveXObject('Microsoft.XMLHTTP')}, +javascript code function() {return new XMLHttpRequest()} +javascript code ) || false; +javascript code }, +javascript blank +javascript code activeRequestCount: 0 +javascript code } +javascript blank +javascript code Ajax.Responders = { +javascript code responders: [], +javascript blank +javascript code _each: function(iterator) { +javascript code this.responders._each(iterator); +javascript code }, +javascript blank +javascript code register: function(responderToAdd) { +javascript code if (!this.include(responderToAdd)) +javascript code this.responders.push(responderToAdd); +javascript code }, +javascript blank +javascript code unregister: function(responderToRemove) { +javascript code this.responders = this.responders.without(responderToRemove); +javascript code }, +javascript blank +javascript code dispatch: function(callback, request, transport, json) { +javascript code this.each(function(responder) { +javascript code if (responder[callback] && typeof responder[callback] == 'function') { +javascript code try { +javascript code responder[callback].apply(responder, [request, transport, json]); +javascript code } catch (e) {} +javascript code } +javascript code }); +javascript code } +javascript code }; +javascript blank +javascript code Object.extend(Ajax.Responders, Enumerable); +javascript blank +javascript code Ajax.Responders.register({ +javascript code onCreate: function() { +javascript code Ajax.activeRequestCount++; +javascript code }, +javascript blank +javascript code onComplete: function() { +javascript code Ajax.activeRequestCount--; +javascript code } +javascript code }); +javascript blank +javascript code Ajax.Base = function() {}; +javascript code Ajax.Base.prototype = { +javascript code setOptions: function(options) { +javascript code this.options = { +javascript code method: 'post', +javascript code asynchronous: true, +javascript code parameters: '' +javascript code } +javascript code Object.extend(this.options, options || {}); +javascript code }, +javascript blank +javascript code responseIsSuccess: function() { +javascript code return this.transport.status == undefined +javascript code || this.transport.status == 0 +javascript code || (this.transport.status >= 200 && this.transport.status < 300); +javascript code }, +javascript blank +javascript code responseIsFailure: function() { +javascript code return !this.responseIsSuccess(); +javascript code } +javascript code } +javascript blank +javascript code Ajax.Request = Class.create(); +javascript code Ajax.Request.Events = +javascript code ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; +javascript blank +javascript code Ajax.Request.prototype = Object.extend(new Ajax.Base(), { +javascript code initialize: function(url, options) { +javascript code this.transport = Ajax.getTransport(); +javascript code this.setOptions(options); +javascript code this.request(url); +javascript code }, +javascript blank +javascript code request: function(url) { +javascript code var parameters = this.options.parameters || ''; +javascript code if (parameters.length > 0) parameters += '&_='; +javascript blank +javascript code try { +javascript code this.url = url; +javascript code if (this.options.method == 'get' && parameters.length > 0) +javascript code this.url += (this.url.match(/\?/) ? '&' : '?') + parameters; +javascript blank +javascript code Ajax.Responders.dispatch('onCreate', this, this.transport); +javascript blank +javascript code this.transport.open(this.options.method, this.url, +javascript code this.options.asynchronous); +javascript blank +javascript code if (this.options.asynchronous) { +javascript code this.transport.onreadystatechange = this.onStateChange.bind(this); +javascript code setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10); +javascript code } +javascript blank +javascript code this.setRequestHeaders(); +javascript blank +javascript code var body = this.options.postBody ? this.options.postBody : parameters; +javascript code this.transport.send(this.options.method == 'post' ? body : null); +javascript blank +javascript code } catch (e) { +javascript code this.dispatchException(e); +javascript code } +javascript code }, +javascript blank +javascript code setRequestHeaders: function() { +javascript code var requestHeaders = +javascript code ['X-Requested-With', 'XMLHttpRequest', +javascript code 'X-Prototype-Version', Prototype.Version]; +javascript blank +javascript code if (this.options.method == 'post') { +javascript code requestHeaders.push('Content-type', +javascript code 'application/x-www-form-urlencoded'); +javascript blank +javascript comment /* Force "Connection: close" for Mozilla browsers to work around +javascript comment * a bug where XMLHttpReqeuest sends an incorrect Content-length +javascript comment * header. See Mozilla Bugzilla #246651. +javascript comment */ +javascript code if (this.transport.overrideMimeType) +javascript code requestHeaders.push('Connection', 'close'); +javascript code } +javascript blank +javascript code if (this.options.requestHeaders) +javascript code requestHeaders.push.apply(requestHeaders, this.options.requestHeaders); +javascript blank +javascript code for (var i = 0; i < requestHeaders.length; i += 2) +javascript code this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]); +javascript code }, +javascript blank +javascript code onStateChange: function() { +javascript code var readyState = this.transport.readyState; +javascript code if (readyState != 1) +javascript code this.respondToReadyState(this.transport.readyState); +javascript code }, +javascript blank +javascript code header: function(name) { +javascript code try { +javascript code return this.transport.getResponseHeader(name); +javascript code } catch (e) {} +javascript code }, +javascript blank +javascript code evalJSON: function() { +javascript code try { +javascript code return eval(this.header('X-JSON')); +javascript code } catch (e) {} +javascript code }, +javascript blank +javascript code evalResponse: function() { +javascript code try { +javascript code return eval(this.transport.responseText); +javascript code } catch (e) { +javascript code this.dispatchException(e); +javascript code } +javascript code }, +javascript blank +javascript code respondToReadyState: function(readyState) { +javascript code var event = Ajax.Request.Events[readyState]; +javascript code var transport = this.transport, json = this.evalJSON(); +javascript blank +javascript code if (event == 'Complete') { +javascript code try { +javascript code (this.options['on' + this.transport.status] +javascript code || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] +javascript code || Prototype.emptyFunction)(transport, json); +javascript code } catch (e) { +javascript code this.dispatchException(e); +javascript code } +javascript blank +javascript code if ((this.header('Content-type') || '').match(/^text\/javascript/i)) +javascript code this.evalResponse(); +javascript code } +javascript blank +javascript code try { +javascript code (this.options['on' + event] || Prototype.emptyFunction)(transport, json); +javascript code Ajax.Responders.dispatch('on' + event, this, transport, json); +javascript code } catch (e) { +javascript code this.dispatchException(e); +javascript code } +javascript blank +javascript comment /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ +javascript code if (event == 'Complete') +javascript code this.transport.onreadystatechange = Prototype.emptyFunction; +javascript code }, +javascript blank +javascript code dispatchException: function(exception) { +javascript code (this.options.onException || Prototype.emptyFunction)(this, exception); +javascript code Ajax.Responders.dispatch('onException', this, exception); +javascript code } +javascript code }); +javascript blank +javascript code Ajax.Updater = Class.create(); +javascript blank +javascript code Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { +javascript code initialize: function(container, url, options) { +javascript code this.containers = { +javascript code success: container.success ? $(container.success) : $(container), +javascript code failure: container.failure ? $(container.failure) : +javascript code (container.success ? null : $(container)) +javascript code } +javascript blank +javascript code this.transport = Ajax.getTransport(); +javascript code this.setOptions(options); +javascript blank +javascript code var onComplete = this.options.onComplete || Prototype.emptyFunction; +javascript code this.options.onComplete = (function(transport, object) { +javascript code this.updateContent(); +javascript code onComplete(transport, object); +javascript code }).bind(this); +javascript blank +javascript code this.request(url); +javascript code }, +javascript blank +javascript code updateContent: function() { +javascript code var receiver = this.responseIsSuccess() ? +javascript code this.containers.success : this.containers.failure; +javascript code var response = this.transport.responseText; +javascript blank +javascript code if (!this.options.evalScripts) +javascript code response = response.stripScripts(); +javascript blank +javascript code if (receiver) { +javascript code if (this.options.insertion) { +javascript code new this.options.insertion(receiver, response); +javascript code } else { +javascript code Element.update(receiver, response); +javascript code } +javascript code } +javascript blank +javascript code if (this.responseIsSuccess()) { +javascript code if (this.onComplete) +javascript code setTimeout(this.onComplete.bind(this), 10); +javascript code } +javascript code } +javascript code }); +javascript blank +javascript code Ajax.PeriodicalUpdater = Class.create(); +javascript code Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), { +javascript code initialize: function(container, url, options) { +javascript code this.setOptions(options); +javascript code this.onComplete = this.options.onComplete; +javascript blank +javascript code this.frequency = (this.options.frequency || 2); +javascript code this.decay = (this.options.decay || 1); +javascript blank +javascript code this.updater = {}; +javascript code this.container = container; +javascript code this.url = url; +javascript blank +javascript code this.start(); +javascript code }, +javascript blank +javascript code start: function() { +javascript code this.options.onComplete = this.updateComplete.bind(this); +javascript code this.onTimerEvent(); +javascript code }, +javascript blank +javascript code stop: function() { +javascript code this.updater.onComplete = undefined; +javascript code clearTimeout(this.timer); +javascript code (this.onComplete || Prototype.emptyFunction).apply(this, arguments); +javascript code }, +javascript blank +javascript code updateComplete: function(request) { +javascript code if (this.options.decay) { +javascript code this.decay = (request.responseText == this.lastText ? +javascript code this.decay * this.options.decay : 1); +javascript blank +javascript code this.lastText = request.responseText; +javascript code } +javascript code this.timer = setTimeout(this.onTimerEvent.bind(this), +javascript code this.decay * this.frequency * 1000); +javascript code }, +javascript blank +javascript code onTimerEvent: function() { +javascript code this.updater = new Ajax.Updater(this.container, this.url, this.options); +javascript code } +javascript code }); +javascript code document.getElementsByClassName = function(className, parentElement) { +javascript code var children = ($(parentElement) || document.body).getElementsByTagName('*'); +javascript code return $A(children).inject([], function(elements, child) { +javascript code if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) +javascript code elements.push(child); +javascript code return elements; +javascript code }); +javascript code } +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code if (!window.Element) { +javascript code var Element = new Object(); +javascript code } +javascript blank +javascript code Object.extend(Element, { +javascript code visible: function(element) { +javascript code return $(element).style.display != 'none'; +javascript code }, +javascript blank +javascript code toggle: function() { +javascript code for (var i = 0; i < arguments.length; i++) { +javascript code var element = $(arguments[i]); +javascript code Element[Element.visible(element) ? 'hide' : 'show'](element); +javascript code } +javascript code }, +javascript blank +javascript code hide: function() { +javascript code for (var i = 0; i < arguments.length; i++) { +javascript code var element = $(arguments[i]); +javascript code element.style.display = 'none'; +javascript code } +javascript code }, +javascript blank +javascript code show: function() { +javascript code for (var i = 0; i < arguments.length; i++) { +javascript code var element = $(arguments[i]); +javascript code element.style.display = ''; +javascript code } +javascript code }, +javascript blank +javascript code remove: function(element) { +javascript code element = $(element); +javascript code element.parentNode.removeChild(element); +javascript code }, +javascript blank +javascript code update: function(element, html) { +javascript code $(element).innerHTML = html.stripScripts(); +javascript code setTimeout(function() {html.evalScripts()}, 10); +javascript code }, +javascript blank +javascript code getHeight: function(element) { +javascript code element = $(element); +javascript code return element.offsetHeight; +javascript code }, +javascript blank +javascript code classNames: function(element) { +javascript code return new Element.ClassNames(element); +javascript code }, +javascript blank +javascript code hasClassName: function(element, className) { +javascript code if (!(element = $(element))) return; +javascript code return Element.classNames(element).include(className); +javascript code }, +javascript blank +javascript code addClassName: function(element, className) { +javascript code if (!(element = $(element))) return; +javascript code return Element.classNames(element).add(className); +javascript code }, +javascript blank +javascript code removeClassName: function(element, className) { +javascript code if (!(element = $(element))) return; +javascript code return Element.classNames(element).remove(className); +javascript code }, +javascript blank +javascript comment // removes whitespace-only text node children +javascript code cleanWhitespace: function(element) { +javascript code element = $(element); +javascript code for (var i = 0; i < element.childNodes.length; i++) { +javascript code var node = element.childNodes[i]; +javascript code if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) +javascript code Element.remove(node); +javascript code } +javascript code }, +javascript blank +javascript code empty: function(element) { +javascript code return $(element).innerHTML.match(/^\s*$/); +javascript code }, +javascript blank +javascript code scrollTo: function(element) { +javascript code element = $(element); +javascript code var x = element.x ? element.x : element.offsetLeft, +javascript code y = element.y ? element.y : element.offsetTop; +javascript code window.scrollTo(x, y); +javascript code }, +javascript blank +javascript code getStyle: function(element, style) { +javascript code element = $(element); +javascript code var value = element.style[style.camelize()]; +javascript code if (!value) { +javascript code if (document.defaultView && document.defaultView.getComputedStyle) { +javascript code var css = document.defaultView.getComputedStyle(element, null); +javascript code value = css ? css.getPropertyValue(style) : null; +javascript code } else if (element.currentStyle) { +javascript code value = element.currentStyle[style.camelize()]; +javascript code } +javascript code } +javascript blank +javascript code if (window.opera && ['left', 'top', 'right', 'bottom'].include(style)) +javascript code if (Element.getStyle(element, 'position') == 'static') value = 'auto'; +javascript blank +javascript code return value == 'auto' ? null : value; +javascript code }, +javascript blank +javascript code setStyle: function(element, style) { +javascript code element = $(element); +javascript code for (name in style) +javascript code element.style[name.camelize()] = style[name]; +javascript code }, +javascript blank +javascript code getDimensions: function(element) { +javascript code element = $(element); +javascript code if (Element.getStyle(element, 'display') != 'none') +javascript code return {width: element.offsetWidth, height: element.offsetHeight}; +javascript blank +javascript comment // All *Width and *Height properties give 0 on elements with display none, +javascript comment // so enable the element temporarily +javascript code var els = element.style; +javascript code var originalVisibility = els.visibility; +javascript code var originalPosition = els.position; +javascript code els.visibility = 'hidden'; +javascript code els.position = 'absolute'; +javascript code els.display = ''; +javascript code var originalWidth = element.clientWidth; +javascript code var originalHeight = element.clientHeight; +javascript code els.display = 'none'; +javascript code els.position = originalPosition; +javascript code els.visibility = originalVisibility; +javascript code return {width: originalWidth, height: originalHeight}; +javascript code }, +javascript blank +javascript code makePositioned: function(element) { +javascript code element = $(element); +javascript code var pos = Element.getStyle(element, 'position'); +javascript code if (pos == 'static' || !pos) { +javascript code element._madePositioned = true; +javascript code element.style.position = 'relative'; +javascript comment // Opera returns the offset relative to the positioning context, when an +javascript comment // element is position relative but top and left have not been defined +javascript code if (window.opera) { +javascript code element.style.top = 0; +javascript code element.style.left = 0; +javascript code } +javascript code } +javascript code }, +javascript blank +javascript code undoPositioned: function(element) { +javascript code element = $(element); +javascript code if (element._madePositioned) { +javascript code element._madePositioned = undefined; +javascript code element.style.position = +javascript code element.style.top = +javascript code element.style.left = +javascript code element.style.bottom = +javascript code element.style.right = ''; +javascript code } +javascript code }, +javascript blank +javascript code makeClipping: function(element) { +javascript code element = $(element); +javascript code if (element._overflow) return; +javascript code element._overflow = element.style.overflow; +javascript code if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden') +javascript code element.style.overflow = 'hidden'; +javascript code }, +javascript blank +javascript code undoClipping: function(element) { +javascript code element = $(element); +javascript code if (element._overflow) return; +javascript code element.style.overflow = element._overflow; +javascript code element._overflow = undefined; +javascript code } +javascript code }); +javascript blank +javascript code var Toggle = new Object(); +javascript code Toggle.display = Element.toggle; +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code Abstract.Insertion = function(adjacency) { +javascript code this.adjacency = adjacency; +javascript code } +javascript blank +javascript code Abstract.Insertion.prototype = { +javascript code initialize: function(element, content) { +javascript code this.element = $(element); +javascript code this.content = content.stripScripts(); +javascript blank +javascript code if (this.adjacency && this.element.insertAdjacentHTML) { +javascript code try { +javascript code this.element.insertAdjacentHTML(this.adjacency, this.content); +javascript code } catch (e) { +javascript code if (this.element.tagName.toLowerCase() == 'tbody') { +javascript code this.insertContent(this.contentFromAnonymousTable()); +javascript code } else { +javascript code throw e; +javascript code } +javascript code } +javascript code } else { +javascript code this.range = this.element.ownerDocument.createRange(); +javascript code if (this.initializeRange) this.initializeRange(); +javascript code this.insertContent([this.range.createContextualFragment(this.content)]); +javascript code } +javascript blank +javascript code setTimeout(function() {content.evalScripts()}, 10); +javascript code }, +javascript blank +javascript code contentFromAnonymousTable: function() { +javascript code var div = document.createElement('div'); +javascript code div.innerHTML = '' + this.content + '
'; +javascript code return $A(div.childNodes[0].childNodes[0].childNodes); +javascript code } +javascript code } +javascript blank +javascript code var Insertion = new Object(); +javascript blank +javascript code Insertion.Before = Class.create(); +javascript code Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), { +javascript code initializeRange: function() { +javascript code this.range.setStartBefore(this.element); +javascript code }, +javascript blank +javascript code insertContent: function(fragments) { +javascript code fragments.each((function(fragment) { +javascript code this.element.parentNode.insertBefore(fragment, this.element); +javascript code }).bind(this)); +javascript code } +javascript code }); +javascript blank +javascript code Insertion.Top = Class.create(); +javascript code Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), { +javascript code initializeRange: function() { +javascript code this.range.selectNodeContents(this.element); +javascript code this.range.collapse(true); +javascript code }, +javascript blank +javascript code insertContent: function(fragments) { +javascript code fragments.reverse(false).each((function(fragment) { +javascript code this.element.insertBefore(fragment, this.element.firstChild); +javascript code }).bind(this)); +javascript code } +javascript code }); +javascript blank +javascript code Insertion.Bottom = Class.create(); +javascript code Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), { +javascript code initializeRange: function() { +javascript code this.range.selectNodeContents(this.element); +javascript code this.range.collapse(this.element); +javascript code }, +javascript blank +javascript code insertContent: function(fragments) { +javascript code fragments.each((function(fragment) { +javascript code this.element.appendChild(fragment); +javascript code }).bind(this)); +javascript code } +javascript code }); +javascript blank +javascript code Insertion.After = Class.create(); +javascript code Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), { +javascript code initializeRange: function() { +javascript code this.range.setStartAfter(this.element); +javascript code }, +javascript blank +javascript code insertContent: function(fragments) { +javascript code fragments.each((function(fragment) { +javascript code this.element.parentNode.insertBefore(fragment, +javascript code this.element.nextSibling); +javascript code }).bind(this)); +javascript code } +javascript code }); +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code Element.ClassNames = Class.create(); +javascript code Element.ClassNames.prototype = { +javascript code initialize: function(element) { +javascript code this.element = $(element); +javascript code }, +javascript blank +javascript code _each: function(iterator) { +javascript code this.element.className.split(/\s+/).select(function(name) { +javascript code return name.length > 0; +javascript code })._each(iterator); +javascript code }, +javascript blank +javascript code set: function(className) { +javascript code this.element.className = className; +javascript code }, +javascript blank +javascript code add: function(classNameToAdd) { +javascript code if (this.include(classNameToAdd)) return; +javascript code this.set(this.toArray().concat(classNameToAdd).join(' ')); +javascript code }, +javascript blank +javascript code remove: function(classNameToRemove) { +javascript code if (!this.include(classNameToRemove)) return; +javascript code this.set(this.select(function(className) { +javascript code return className != classNameToRemove; +javascript code }).join(' ')); +javascript code }, +javascript blank +javascript code toString: function() { +javascript code return this.toArray().join(' '); +javascript code } +javascript code } +javascript blank +javascript code Object.extend(Element.ClassNames.prototype, Enumerable); +javascript code var Field = { +javascript code clear: function() { +javascript code for (var i = 0; i < arguments.length; i++) +javascript code $(arguments[i]).value = ''; +javascript code }, +javascript blank +javascript code focus: function(element) { +javascript code $(element).focus(); +javascript code }, +javascript blank +javascript code present: function() { +javascript code for (var i = 0; i < arguments.length; i++) +javascript code if ($(arguments[i]).value == '') return false; +javascript code return true; +javascript code }, +javascript blank +javascript code select: function(element) { +javascript code $(element).select(); +javascript code }, +javascript blank +javascript code activate: function(element) { +javascript code element = $(element); +javascript code element.focus(); +javascript code if (element.select) +javascript code element.select(); +javascript code } +javascript code } +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code var Form = { +javascript code serialize: function(form) { +javascript code var elements = Form.getElements($(form)); +javascript code var queryComponents = new Array(); +javascript blank +javascript code for (var i = 0; i < elements.length; i++) { +javascript code var queryComponent = Form.Element.serialize(elements[i]); +javascript code if (queryComponent) +javascript code queryComponents.push(queryComponent); +javascript code } +javascript blank +javascript code return queryComponents.join('&'); +javascript code }, +javascript blank +javascript code getElements: function(form) { +javascript code form = $(form); +javascript code var elements = new Array(); +javascript blank +javascript code for (tagName in Form.Element.Serializers) { +javascript code var tagElements = form.getElementsByTagName(tagName); +javascript code for (var j = 0; j < tagElements.length; j++) +javascript code elements.push(tagElements[j]); +javascript code } +javascript code return elements; +javascript code }, +javascript blank +javascript code getInputs: function(form, typeName, name) { +javascript code form = $(form); +javascript code var inputs = form.getElementsByTagName('input'); +javascript blank +javascript code if (!typeName && !name) +javascript code return inputs; +javascript blank +javascript code var matchingInputs = new Array(); +javascript code for (var i = 0; i < inputs.length; i++) { +javascript code var input = inputs[i]; +javascript code if ((typeName && input.type != typeName) || +javascript code (name && input.name != name)) +javascript code continue; +javascript code matchingInputs.push(input); +javascript code } +javascript blank +javascript code return matchingInputs; +javascript code }, +javascript blank +javascript code disable: function(form) { +javascript code var elements = Form.getElements(form); +javascript code for (var i = 0; i < elements.length; i++) { +javascript code var element = elements[i]; +javascript code element.blur(); +javascript code element.disabled = 'true'; +javascript code } +javascript code }, +javascript blank +javascript code enable: function(form) { +javascript code var elements = Form.getElements(form); +javascript code for (var i = 0; i < elements.length; i++) { +javascript code var element = elements[i]; +javascript code element.disabled = ''; +javascript code } +javascript code }, +javascript blank +javascript code findFirstElement: function(form) { +javascript code return Form.getElements(form).find(function(element) { +javascript code return element.type != 'hidden' && !element.disabled && +javascript code ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); +javascript code }); +javascript code }, +javascript blank +javascript code focusFirstElement: function(form) { +javascript code Field.activate(Form.findFirstElement(form)); +javascript code }, +javascript blank +javascript code reset: function(form) { +javascript code $(form).reset(); +javascript code } +javascript code } +javascript blank +javascript code Form.Element = { +javascript code serialize: function(element) { +javascript code element = $(element); +javascript code var method = element.tagName.toLowerCase(); +javascript code var parameter = Form.Element.Serializers[method](element); +javascript blank +javascript code if (parameter) { +javascript code var key = encodeURIComponent(parameter[0]); +javascript code if (key.length == 0) return; +javascript blank +javascript code if (parameter[1].constructor != Array) +javascript code parameter[1] = [parameter[1]]; +javascript blank +javascript code return parameter[1].map(function(value) { +javascript code return key + '=' + encodeURIComponent(value); +javascript code }).join('&'); +javascript code } +javascript code }, +javascript blank +javascript code getValue: function(element) { +javascript code element = $(element); +javascript code var method = element.tagName.toLowerCase(); +javascript code var parameter = Form.Element.Serializers[method](element); +javascript blank +javascript code if (parameter) +javascript code return parameter[1]; +javascript code } +javascript code } +javascript blank +javascript code Form.Element.Serializers = { +javascript code input: function(element) { +javascript code switch (element.type.toLowerCase()) { +javascript code case 'submit': +javascript code case 'hidden': +javascript code case 'password': +javascript code case 'text': +javascript code return Form.Element.Serializers.textarea(element); +javascript code case 'checkbox': +javascript code case 'radio': +javascript code return Form.Element.Serializers.inputSelector(element); +javascript code } +javascript code return false; +javascript code }, +javascript blank +javascript code inputSelector: function(element) { +javascript code if (element.checked) +javascript code return [element.name, element.value]; +javascript code }, +javascript blank +javascript code textarea: function(element) { +javascript code return [element.name, element.value]; +javascript code }, +javascript blank +javascript code select: function(element) { +javascript code return Form.Element.Serializers[element.type == 'select-one' ? +javascript code 'selectOne' : 'selectMany'](element); +javascript code }, +javascript blank +javascript code selectOne: function(element) { +javascript code var value = '', opt, index = element.selectedIndex; +javascript code if (index >= 0) { +javascript code opt = element.options[index]; +javascript code value = opt.value; +javascript code if (!value && !('value' in opt)) +javascript code value = opt.text; +javascript code } +javascript code return [element.name, value]; +javascript code }, +javascript blank +javascript code selectMany: function(element) { +javascript code var value = new Array(); +javascript code for (var i = 0; i < element.length; i++) { +javascript code var opt = element.options[i]; +javascript code if (opt.selected) { +javascript code var optValue = opt.value; +javascript code if (!optValue && !('value' in opt)) +javascript code optValue = opt.text; +javascript code value.push(optValue); +javascript code } +javascript code } +javascript code return [element.name, value]; +javascript code } +javascript code } +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code var $F = Form.Element.getValue; +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code Abstract.TimedObserver = function() {} +javascript code Abstract.TimedObserver.prototype = { +javascript code initialize: function(element, frequency, callback) { +javascript code this.frequency = frequency; +javascript code this.element = $(element); +javascript code this.callback = callback; +javascript blank +javascript code this.lastValue = this.getValue(); +javascript code this.registerCallback(); +javascript code }, +javascript blank +javascript code registerCallback: function() { +javascript code setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); +javascript code }, +javascript blank +javascript code onTimerEvent: function() { +javascript code var value = this.getValue(); +javascript code if (this.lastValue != value) { +javascript code this.callback(this.element, value); +javascript code this.lastValue = value; +javascript code } +javascript code } +javascript code } +javascript blank +javascript code Form.Element.Observer = Class.create(); +javascript code Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { +javascript code getValue: function() { +javascript code return Form.Element.getValue(this.element); +javascript code } +javascript code }); +javascript blank +javascript code Form.Observer = Class.create(); +javascript code Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { +javascript code getValue: function() { +javascript code return Form.serialize(this.element); +javascript code } +javascript code }); +javascript blank +javascript comment /*--------------------------------------------------------------------------*/ +javascript blank +javascript code Abstract.EventObserver = function() {} +javascript code Abstract.EventObserver.prototype = { +javascript code initialize: function(element, callback) { +javascript code this.element = $(element); +javascript code this.callback = callback; +javascript blank +javascript code this.lastValue = this.getValue(); +javascript code if (this.element.tagName.toLowerCase() == 'form') +javascript code this.registerFormCallbacks(); +javascript code else +javascript code this.registerCallback(this.element); +javascript code }, +javascript blank +javascript code onElementEvent: function() { +javascript code var value = this.getValue(); +javascript code if (this.lastValue != value) { +javascript code this.callback(this.element, value); +javascript code this.lastValue = value; +javascript code } +javascript code }, +javascript blank +javascript code registerFormCallbacks: function() { +javascript code var elements = Form.getElements(this.element); +javascript code for (var i = 0; i < elements.length; i++) +javascript code this.registerCallback(elements[i]); +javascript code }, +javascript blank +javascript code registerCallback: function(element) { +javascript code if (element.type) { +javascript code switch (element.type.toLowerCase()) { +javascript code case 'checkbox': +javascript code case 'radio': +javascript code Event.observe(element, 'click', this.onElementEvent.bind(this)); +javascript code break; +javascript code case 'password': +javascript code case 'text': +javascript code case 'textarea': +javascript code case 'select-one': +javascript code case 'select-multiple': +javascript code Event.observe(element, 'change', this.onElementEvent.bind(this)); +javascript code break; +javascript code } +javascript code } +javascript code } +javascript code } +javascript blank +javascript code Form.Element.EventObserver = Class.create(); +javascript code Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { +javascript code getValue: function() { +javascript code return Form.Element.getValue(this.element); +javascript code } +javascript code }); +javascript blank +javascript code Form.EventObserver = Class.create(); +javascript code Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { +javascript code getValue: function() { +javascript code return Form.serialize(this.element); +javascript code } +javascript code }); +javascript code if (!window.Event) { +javascript code var Event = new Object(); +javascript code } +javascript blank +javascript code Object.extend(Event, { +javascript code KEY_BACKSPACE: 8, +javascript code KEY_TAB: 9, +javascript code KEY_RETURN: 13, +javascript code KEY_ESC: 27, +javascript code KEY_LEFT: 37, +javascript code KEY_UP: 38, +javascript code KEY_RIGHT: 39, +javascript code KEY_DOWN: 40, +javascript code KEY_DELETE: 46, +javascript blank +javascript code element: function(event) { +javascript code return event.target || event.srcElement; +javascript code }, +javascript blank +javascript code isLeftClick: function(event) { +javascript code return (((event.which) && (event.which == 1)) || +javascript code ((event.button) && (event.button == 1))); +javascript code }, +javascript blank +javascript code pointerX: function(event) { +javascript code return event.pageX || (event.clientX + +javascript code (document.documentElement.scrollLeft || document.body.scrollLeft)); +javascript code }, +javascript blank +javascript code pointerY: function(event) { +javascript code return event.pageY || (event.clientY + +javascript code (document.documentElement.scrollTop || document.body.scrollTop)); +javascript code }, +javascript blank +javascript code stop: function(event) { +javascript code if (event.preventDefault) { +javascript code event.preventDefault(); +javascript code event.stopPropagation(); +javascript code } else { +javascript code event.returnValue = false; +javascript code event.cancelBubble = true; +javascript code } +javascript code }, +javascript blank +javascript comment // find the first node with the given tagName, starting from the +javascript comment // node the event was triggered on; traverses the DOM upwards +javascript code findElement: function(event, tagName) { +javascript code var element = Event.element(event); +javascript code while (element.parentNode && (!element.tagName || +javascript code (element.tagName.toUpperCase() != tagName.toUpperCase()))) +javascript code element = element.parentNode; +javascript code return element; +javascript code }, +javascript blank +javascript code observers: false, +javascript blank +javascript code _observeAndCache: function(element, name, observer, useCapture) { +javascript code if (!this.observers) this.observers = []; +javascript code if (element.addEventListener) { +javascript code this.observers.push([element, name, observer, useCapture]); +javascript code element.addEventListener(name, observer, useCapture); +javascript code } else if (element.attachEvent) { +javascript code this.observers.push([element, name, observer, useCapture]); +javascript code element.attachEvent('on' + name, observer); +javascript code } +javascript code }, +javascript blank +javascript code unloadCache: function() { +javascript code if (!Event.observers) return; +javascript code for (var i = 0; i < Event.observers.length; i++) { +javascript code Event.stopObserving.apply(this, Event.observers[i]); +javascript code Event.observers[i][0] = null; +javascript code } +javascript code Event.observers = false; +javascript code }, +javascript blank +javascript code observe: function(element, name, observer, useCapture) { +javascript code var element = $(element); +javascript code useCapture = useCapture || false; +javascript blank +javascript code if (name == 'keypress' && +javascript code (navigator.appVersion.match(/Konqueror|Safari|KHTML/) +javascript code || element.attachEvent)) +javascript code name = 'keydown'; +javascript blank +javascript code this._observeAndCache(element, name, observer, useCapture); +javascript code }, +javascript blank +javascript code stopObserving: function(element, name, observer, useCapture) { +javascript code var element = $(element); +javascript code useCapture = useCapture || false; +javascript blank +javascript code if (name == 'keypress' && +javascript code (navigator.appVersion.match(/Konqueror|Safari|KHTML/) +javascript code || element.detachEvent)) +javascript code name = 'keydown'; +javascript blank +javascript code if (element.removeEventListener) { +javascript code element.removeEventListener(name, observer, useCapture); +javascript code } else if (element.detachEvent) { +javascript code element.detachEvent('on' + name, observer); +javascript code } +javascript code } +javascript code }); +javascript blank +javascript comment /* prevent memory leaks in IE */ +javascript code Event.observe(window, 'unload', Event.unloadCache, false); +javascript code var Position = { +javascript comment // set to true if needed, warning: firefox performance problems +javascript comment // NOT neeeded for page scrolling, only if draggable contained in +javascript comment // scrollable elements +javascript code includeScrollOffsets: false, +javascript blank +javascript comment // must be called before calling withinIncludingScrolloffset, every time the +javascript comment // page is scrolled +javascript code prepare: function() { +javascript code this.deltaX = window.pageXOffset +javascript code || document.documentElement.scrollLeft +javascript code || document.body.scrollLeft +javascript code || 0; +javascript code this.deltaY = window.pageYOffset +javascript code || document.documentElement.scrollTop +javascript code || document.body.scrollTop +javascript code || 0; +javascript code }, +javascript blank +javascript code realOffset: function(element) { +javascript code var valueT = 0, valueL = 0; +javascript code do { +javascript code valueT += element.scrollTop || 0; +javascript code valueL += element.scrollLeft || 0; +javascript code element = element.parentNode; +javascript code } while (element); +javascript code return [valueL, valueT]; +javascript code }, +javascript blank +javascript code cumulativeOffset: function(element) { +javascript code var valueT = 0, valueL = 0; +javascript code do { +javascript code valueT += element.offsetTop || 0; +javascript code valueL += element.offsetLeft || 0; +javascript code element = element.offsetParent; +javascript code } while (element); +javascript code return [valueL, valueT]; +javascript code }, +javascript blank +javascript code positionedOffset: function(element) { +javascript code var valueT = 0, valueL = 0; +javascript code do { +javascript code valueT += element.offsetTop || 0; +javascript code valueL += element.offsetLeft || 0; +javascript code element = element.offsetParent; +javascript code if (element) { +javascript code p = Element.getStyle(element, 'position'); +javascript code if (p == 'relative' || p == 'absolute') break; +javascript code } +javascript code } while (element); +javascript code return [valueL, valueT]; +javascript code }, +javascript blank +javascript code offsetParent: function(element) { +javascript code if (element.offsetParent) return element.offsetParent; +javascript code if (element == document.body) return element; +javascript blank +javascript code while ((element = element.parentNode) && element != document.body) +javascript code if (Element.getStyle(element, 'position') != 'static') +javascript code return element; +javascript blank +javascript code return document.body; +javascript code }, +javascript blank +javascript comment // caches x/y coordinate pair to use with overlap +javascript code within: function(element, x, y) { +javascript code if (this.includeScrollOffsets) +javascript code return this.withinIncludingScrolloffsets(element, x, y); +javascript code this.xcomp = x; +javascript code this.ycomp = y; +javascript code this.offset = this.cumulativeOffset(element); +javascript blank +javascript code return (y >= this.offset[1] && +javascript code y < this.offset[1] + element.offsetHeight && +javascript code x >= this.offset[0] && +javascript code x < this.offset[0] + element.offsetWidth); +javascript code }, +javascript blank +javascript code withinIncludingScrolloffsets: function(element, x, y) { +javascript code var offsetcache = this.realOffset(element); +javascript blank +javascript code this.xcomp = x + offsetcache[0] - this.deltaX; +javascript code this.ycomp = y + offsetcache[1] - this.deltaY; +javascript code this.offset = this.cumulativeOffset(element); +javascript blank +javascript code return (this.ycomp >= this.offset[1] && +javascript code this.ycomp < this.offset[1] + element.offsetHeight && +javascript code this.xcomp >= this.offset[0] && +javascript code this.xcomp < this.offset[0] + element.offsetWidth); +javascript code }, +javascript blank +javascript comment // within must be called directly before +javascript code overlap: function(mode, element) { +javascript code if (!mode) return 0; +javascript code if (mode == 'vertical') +javascript code return ((this.offset[1] + element.offsetHeight) - this.ycomp) / +javascript code element.offsetHeight; +javascript code if (mode == 'horizontal') +javascript code return ((this.offset[0] + element.offsetWidth) - this.xcomp) / +javascript code element.offsetWidth; +javascript code }, +javascript blank +javascript code clone: function(source, target) { +javascript code source = $(source); +javascript code target = $(target); +javascript code target.style.position = 'absolute'; +javascript code var offsets = this.cumulativeOffset(source); +javascript code target.style.top = offsets[1] + 'px'; +javascript code target.style.left = offsets[0] + 'px'; +javascript code target.style.width = source.offsetWidth + 'px'; +javascript code target.style.height = source.offsetHeight + 'px'; +javascript code }, +javascript blank +javascript code page: function(forElement) { +javascript code var valueT = 0, valueL = 0; +javascript blank +javascript code var element = forElement; +javascript code do { +javascript code valueT += element.offsetTop || 0; +javascript code valueL += element.offsetLeft || 0; +javascript blank +javascript comment // Safari fix +javascript code if (element.offsetParent==document.body) +javascript code if (Element.getStyle(element,'position')=='absolute') break; +javascript blank +javascript code } while (element = element.offsetParent); +javascript blank +javascript code element = forElement; +javascript code do { +javascript code valueT -= element.scrollTop || 0; +javascript code valueL -= element.scrollLeft || 0; +javascript code } while (element = element.parentNode); +javascript blank +javascript code return [valueL, valueT]; +javascript code }, +javascript blank +javascript code clone: function(source, target) { +javascript code var options = Object.extend({ +javascript code setLeft: true, +javascript code setTop: true, +javascript code setWidth: true, +javascript code setHeight: true, +javascript code offsetTop: 0, +javascript code offsetLeft: 0 +javascript code }, arguments[2] || {}) +javascript blank +javascript comment // find page position of source +javascript code source = $(source); +javascript code var p = Position.page(source); +javascript blank +javascript comment // find coordinate system to use +javascript code target = $(target); +javascript code var delta = [0, 0]; +javascript code var parent = null; +javascript comment // delta [0,0] will do fine with position: fixed elements, +javascript comment // position:absolute needs offsetParent deltas +javascript code if (Element.getStyle(target,'position') == 'absolute') { +javascript code parent = Position.offsetParent(target); +javascript code delta = Position.page(parent); +javascript code } +javascript blank +javascript comment // correct by body offsets (fixes Safari) +javascript code if (parent == document.body) { +javascript code delta[0] -= document.body.offsetLeft; +javascript code delta[1] -= document.body.offsetTop; +javascript code } +javascript blank +javascript comment // set position +javascript code if(options.setLeft) target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; +javascript code if(options.setTop) target.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; +javascript code if(options.setWidth) target.style.width = source.offsetWidth + 'px'; +javascript code if(options.setHeight) target.style.height = source.offsetHeight + 'px'; +javascript code }, +javascript blank +javascript code absolutize: function(element) { +javascript code element = $(element); +javascript code if (element.style.position == 'absolute') return; +javascript code Position.prepare(); +javascript blank +javascript code var offsets = Position.positionedOffset(element); +javascript code var top = offsets[1]; +javascript code var left = offsets[0]; +javascript code var width = element.clientWidth; +javascript code var height = element.clientHeight; +javascript blank +javascript code element._originalLeft = left - parseFloat(element.style.left || 0); +javascript code element._originalTop = top - parseFloat(element.style.top || 0); +javascript code element._originalWidth = element.style.width; +javascript code element._originalHeight = element.style.height; +javascript blank +javascript code element.style.position = 'absolute'; +javascript code element.style.top = top + 'px';; +javascript code element.style.left = left + 'px';; +javascript code element.style.width = width + 'px';; +javascript code element.style.height = height + 'px';; +javascript code }, +javascript blank +javascript code relativize: function(element) { +javascript code element = $(element); +javascript code if (element.style.position == 'relative') return; +javascript code Position.prepare(); +javascript blank +javascript code element.style.position = 'relative'; +javascript code var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); +javascript code var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); +javascript blank +javascript code element.style.top = top + 'px'; +javascript code element.style.left = left + 'px'; +javascript code element.style.height = element._originalHeight; +javascript code element.style.width = element._originalWidth; +javascript code } +javascript code } +javascript blank +javascript comment // Safari returns margins on body which is incorrect if the child is absolutely +javascript comment // positioned. For performance reasons, redefine Position.cumulativeOffset for +javascript comment // KHTML/WebKit only. +javascript code if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) { +javascript code Position.cumulativeOffset = function(element) { +javascript code var valueT = 0, valueL = 0; +javascript code do { +javascript code valueT += element.offsetTop || 0; +javascript code valueL += element.offsetLeft || 0; +javascript code if (element.offsetParent == document.body) +javascript code if (Element.getStyle(element, 'position') == 'absolute') break; +javascript blank +javascript code element = element.offsetParent; +javascript code } while (element); +javascript blank +javascript code return [valueL, valueT]; +javascript code } +javascript code } diff --git a/test/expected_dir/js1.js/javascript/code b/test/expected_dir/js1.js/javascript/code deleted file mode 100644 index 134332a..0000000 --- a/test/expected_dir/js1.js/javascript/code +++ /dev/null @@ -1,1446 +0,0 @@ -var Prototype = { -Version: '1.4.0', -ScriptFragment: '(?:)((\n|\r|.)*?)(?:<\/script>)', -emptyFunction: function() {}, -K: function(x) {return x} -} -var Class = { -create: function() { -return function() { -this.initialize.apply(this, arguments); -} -} -} -var Abstract = new Object(); -Object.extend = function(destination, source) { -for (property in source) { -destination[property] = source[property]; -} -return destination; -} -Object.inspect = function(object) { -try { -if (object == undefined) return 'undefined'; -if (object == null) return 'null'; -return object.inspect ? object.inspect() : object.toString(); -} catch (e) { -if (e instanceof RangeError) return '...'; -throw e; -} -} -Function.prototype.bind = function() { -var __method = this, args = $A(arguments), object = args.shift(); -return function() { -return __method.apply(object, args.concat($A(arguments))); -} -} -Function.prototype.bindAsEventListener = function(object) { -var __method = this; -return function(event) { -return __method.call(object, event || window.event); -} -} -Object.extend(Number.prototype, { -toColorPart: function() { -var digits = this.toString(16); -if (this < 16) return '0' + digits; -return digits; -}, -succ: function() { -return this + 1; -}, -times: function(iterator) { -$R(0, this, true).each(iterator); -return this; -} -}); -var Try = { -these: function() { -var returnValue; -for (var i = 0; i < arguments.length; i++) { -var lambda = arguments[i]; -try { -returnValue = lambda(); -break; -} catch (e) {} -} -return returnValue; -} -} -var PeriodicalExecuter = Class.create(); -PeriodicalExecuter.prototype = { -initialize: function(callback, frequency) { -this.callback = callback; -this.frequency = frequency; -this.currentlyExecuting = false; -this.registerCallback(); -}, -registerCallback: function() { -setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); -}, -onTimerEvent: function() { -if (!this.currentlyExecuting) { -try { -this.currentlyExecuting = true; -this.callback(); -} finally { -this.currentlyExecuting = false; -} -} -} -} -function $() { -var elements = new Array(); -for (var i = 0; i < arguments.length; i++) { -var element = arguments[i]; -if (typeof element == 'string') -element = document.getElementById(element); -if (arguments.length == 1) -return element; -elements.push(element); -} -return elements; -} -Object.extend(String.prototype, { -stripTags: function() { -return this.replace(/<\/?[^>]+>/gi, ''); -}, -stripScripts: function() { -return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); -}, -extractScripts: function() { -var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); -var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); -return (this.match(matchAll) || []).map(function(scriptTag) { -return (scriptTag.match(matchOne) || ['', ''])[1]; -}); -}, -evalScripts: function() { -return this.extractScripts().map(eval); -}, -escapeHTML: function() { -var div = document.createElement('div'); -var text = document.createTextNode(this); -div.appendChild(text); -return div.innerHTML; -}, -unescapeHTML: function() { -var div = document.createElement('div'); -div.innerHTML = this.stripTags(); -return div.childNodes[0] ? div.childNodes[0].nodeValue : ''; -}, -toQueryParams: function() { -var pairs = this.match(/^\??(.*)$/)[1].split('&'); -return pairs.inject({}, function(params, pairString) { -var pair = pairString.split('='); -params[pair[0]] = pair[1]; -return params; -}); -}, -toArray: function() { -return this.split(''); -}, -camelize: function() { -var oStringList = this.split('-'); -if (oStringList.length == 1) return oStringList[0]; -var camelizedString = this.indexOf('-') == 0 -? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) -: oStringList[0]; -for (var i = 1, len = oStringList.length; i < len; i++) { -var s = oStringList[i]; -camelizedString += s.charAt(0).toUpperCase() + s.substring(1); -} -return camelizedString; -}, -inspect: function() { -return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'"; -} -}); -String.prototype.parseQuery = String.prototype.toQueryParams; -var $break = new Object(); -var $continue = new Object(); -var Enumerable = { -each: function(iterator) { -var index = 0; -try { -this._each(function(value) { -try { -iterator(value, index++); -} catch (e) { -if (e != $continue) throw e; -} -}); -} catch (e) { -if (e != $break) throw e; -} -}, -all: function(iterator) { -var result = true; -this.each(function(value, index) { -result = result && !!(iterator || Prototype.K)(value, index); -if (!result) throw $break; -}); -return result; -}, -any: function(iterator) { -var result = true; -this.each(function(value, index) { -if (result = !!(iterator || Prototype.K)(value, index)) -throw $break; -}); -return result; -}, -collect: function(iterator) { -var results = []; -this.each(function(value, index) { -results.push(iterator(value, index)); -}); -return results; -}, -detect: function (iterator) { -var result; -this.each(function(value, index) { -if (iterator(value, index)) { -result = value; -throw $break; -} -}); -return result; -}, -findAll: function(iterator) { -var results = []; -this.each(function(value, index) { -if (iterator(value, index)) -results.push(value); -}); -return results; -}, -grep: function(pattern, iterator) { -var results = []; -this.each(function(value, index) { -var stringValue = value.toString(); -if (stringValue.match(pattern)) -results.push((iterator || Prototype.K)(value, index)); -}) -return results; -}, -include: function(object) { -var found = false; -this.each(function(value) { -if (value == object) { -found = true; -throw $break; -} -}); -return found; -}, -inject: function(memo, iterator) { -this.each(function(value, index) { -memo = iterator(memo, value, index); -}); -return memo; -}, -invoke: function(method) { -var args = $A(arguments).slice(1); -return this.collect(function(value) { -return value[method].apply(value, args); -}); -}, -max: function(iterator) { -var result; -this.each(function(value, index) { -value = (iterator || Prototype.K)(value, index); -if (value >= (result || value)) -result = value; -}); -return result; -}, -min: function(iterator) { -var result; -this.each(function(value, index) { -value = (iterator || Prototype.K)(value, index); -if (value <= (result || value)) -result = value; -}); -return result; -}, -partition: function(iterator) { -var trues = [], falses = []; -this.each(function(value, index) { -((iterator || Prototype.K)(value, index) ? -trues : falses).push(value); -}); -return [trues, falses]; -}, -pluck: function(property) { -var results = []; -this.each(function(value, index) { -results.push(value[property]); -}); -return results; -}, -reject: function(iterator) { -var results = []; -this.each(function(value, index) { -if (!iterator(value, index)) -results.push(value); -}); -return results; -}, -sortBy: function(iterator) { -return this.collect(function(value, index) { -return {value: value, criteria: iterator(value, index)}; -}).sort(function(left, right) { -var a = left.criteria, b = right.criteria; -return a < b ? -1 : a > b ? 1 : 0; -}).pluck('value'); -}, -toArray: function() { -return this.collect(Prototype.K); -}, -zip: function() { -var iterator = Prototype.K, args = $A(arguments); -if (typeof args.last() == 'function') -iterator = args.pop(); -var collections = [this].concat(args).map($A); -return this.map(function(value, index) { -iterator(value = collections.pluck(index)); -return value; -}); -}, -inspect: function() { -return '#'; -} -} -Object.extend(Enumerable, { -map: Enumerable.collect, -find: Enumerable.detect, -select: Enumerable.findAll, -member: Enumerable.include, -entries: Enumerable.toArray -}); -var $A = Array.from = function(iterable) { -if (!iterable) return []; -if (iterable.toArray) { -return iterable.toArray(); -} else { -var results = []; -for (var i = 0; i < iterable.length; i++) -results.push(iterable[i]); -return results; -} -} -Object.extend(Array.prototype, Enumerable); -Array.prototype._reverse = Array.prototype.reverse; -Object.extend(Array.prototype, { -_each: function(iterator) { -for (var i = 0; i < this.length; i++) -iterator(this[i]); -}, -clear: function() { -this.length = 0; -return this; -}, -first: function() { -return this[0]; -}, -last: function() { -return this[this.length - 1]; -}, -compact: function() { -return this.select(function(value) { -return value != undefined || value != null; -}); -}, -flatten: function() { -return this.inject([], function(array, value) { -return array.concat(value.constructor == Array ? -value.flatten() : [value]); -}); -}, -without: function() { -var values = $A(arguments); -return this.select(function(value) { -return !values.include(value); -}); -}, -indexOf: function(object) { -for (var i = 0; i < this.length; i++) -if (this[i] == object) return i; -return -1; -}, -reverse: function(inline) { -return (inline !== false ? this : this.toArray())._reverse(); -}, -shift: function() { -var result = this[0]; -for (var i = 0; i < this.length - 1; i++) -this[i] = this[i + 1]; -this.length--; -return result; -}, -inspect: function() { -return '[' + this.map(Object.inspect).join(', ') + ']'; -} -}); -var Hash = { -_each: function(iterator) { -for (key in this) { -var value = this[key]; -if (typeof value == 'function') continue; -var pair = [key, value]; -pair.key = key; -pair.value = value; -iterator(pair); -} -}, -keys: function() { -return this.pluck('key'); -}, -values: function() { -return this.pluck('value'); -}, -merge: function(hash) { -return $H(hash).inject($H(this), function(mergedHash, pair) { -mergedHash[pair.key] = pair.value; -return mergedHash; -}); -}, -toQueryString: function() { -return this.map(function(pair) { -return pair.map(encodeURIComponent).join('='); -}).join('&'); -}, -inspect: function() { -return '#'; -} -} -function $H(object) { -var hash = Object.extend({}, object || {}); -Object.extend(hash, Enumerable); -Object.extend(hash, Hash); -return hash; -} -ObjectRange = Class.create(); -Object.extend(ObjectRange.prototype, Enumerable); -Object.extend(ObjectRange.prototype, { -initialize: function(start, end, exclusive) { -this.start = start; -this.end = end; -this.exclusive = exclusive; -}, -_each: function(iterator) { -var value = this.start; -do { -iterator(value); -value = value.succ(); -} while (this.include(value)); -}, -include: function(value) { -if (value < this.start) -return false; -if (this.exclusive) -return value < this.end; -return value <= this.end; -} -}); -var $R = function(start, end, exclusive) { -return new ObjectRange(start, end, exclusive); -} -var Ajax = { -getTransport: function() { -return Try.these( -function() {return new ActiveXObject('Msxml2.XMLHTTP')}, -function() {return new ActiveXObject('Microsoft.XMLHTTP')}, -function() {return new XMLHttpRequest()} -) || false; -}, -activeRequestCount: 0 -} -Ajax.Responders = { -responders: [], -_each: function(iterator) { -this.responders._each(iterator); -}, -register: function(responderToAdd) { -if (!this.include(responderToAdd)) -this.responders.push(responderToAdd); -}, -unregister: function(responderToRemove) { -this.responders = this.responders.without(responderToRemove); -}, -dispatch: function(callback, request, transport, json) { -this.each(function(responder) { -if (responder[callback] && typeof responder[callback] == 'function') { -try { -responder[callback].apply(responder, [request, transport, json]); -} catch (e) {} -} -}); -} -}; -Object.extend(Ajax.Responders, Enumerable); -Ajax.Responders.register({ -onCreate: function() { -Ajax.activeRequestCount++; -}, -onComplete: function() { -Ajax.activeRequestCount--; -} -}); -Ajax.Base = function() {}; -Ajax.Base.prototype = { -setOptions: function(options) { -this.options = { -method: 'post', -asynchronous: true, -parameters: '' -} -Object.extend(this.options, options || {}); -}, -responseIsSuccess: function() { -return this.transport.status == undefined -|| this.transport.status == 0 -|| (this.transport.status >= 200 && this.transport.status < 300); -}, -responseIsFailure: function() { -return !this.responseIsSuccess(); -} -} -Ajax.Request = Class.create(); -Ajax.Request.Events = -['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; -Ajax.Request.prototype = Object.extend(new Ajax.Base(), { -initialize: function(url, options) { -this.transport = Ajax.getTransport(); -this.setOptions(options); -this.request(url); -}, -request: function(url) { -var parameters = this.options.parameters || ''; -if (parameters.length > 0) parameters += '&_='; -try { -this.url = url; -if (this.options.method == 'get' && parameters.length > 0) -this.url += (this.url.match(/\?/) ? '&' : '?') + parameters; -Ajax.Responders.dispatch('onCreate', this, this.transport); -this.transport.open(this.options.method, this.url, -this.options.asynchronous); -if (this.options.asynchronous) { -this.transport.onreadystatechange = this.onStateChange.bind(this); -setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10); -} -this.setRequestHeaders(); -var body = this.options.postBody ? this.options.postBody : parameters; -this.transport.send(this.options.method == 'post' ? body : null); -} catch (e) { -this.dispatchException(e); -} -}, -setRequestHeaders: function() { -var requestHeaders = -['X-Requested-With', 'XMLHttpRequest', -'X-Prototype-Version', Prototype.Version]; -if (this.options.method == 'post') { -requestHeaders.push('Content-type', -'application/x-www-form-urlencoded'); -if (this.transport.overrideMimeType) -requestHeaders.push('Connection', 'close'); -} -if (this.options.requestHeaders) -requestHeaders.push.apply(requestHeaders, this.options.requestHeaders); -for (var i = 0; i < requestHeaders.length; i += 2) -this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]); -}, -onStateChange: function() { -var readyState = this.transport.readyState; -if (readyState != 1) -this.respondToReadyState(this.transport.readyState); -}, -header: function(name) { -try { -return this.transport.getResponseHeader(name); -} catch (e) {} -}, -evalJSON: function() { -try { -return eval(this.header('X-JSON')); -} catch (e) {} -}, -evalResponse: function() { -try { -return eval(this.transport.responseText); -} catch (e) { -this.dispatchException(e); -} -}, -respondToReadyState: function(readyState) { -var event = Ajax.Request.Events[readyState]; -var transport = this.transport, json = this.evalJSON(); -if (event == 'Complete') { -try { -(this.options['on' + this.transport.status] -|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] -|| Prototype.emptyFunction)(transport, json); -} catch (e) { -this.dispatchException(e); -} -if ((this.header('Content-type') || '').match(/^text\/javascript/i)) -this.evalResponse(); -} -try { -(this.options['on' + event] || Prototype.emptyFunction)(transport, json); -Ajax.Responders.dispatch('on' + event, this, transport, json); -} catch (e) { -this.dispatchException(e); -} -if (event == 'Complete') -this.transport.onreadystatechange = Prototype.emptyFunction; -}, -dispatchException: function(exception) { -(this.options.onException || Prototype.emptyFunction)(this, exception); -Ajax.Responders.dispatch('onException', this, exception); -} -}); -Ajax.Updater = Class.create(); -Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { -initialize: function(container, url, options) { -this.containers = { -success: container.success ? $(container.success) : $(container), -failure: container.failure ? $(container.failure) : -(container.success ? null : $(container)) -} -this.transport = Ajax.getTransport(); -this.setOptions(options); -var onComplete = this.options.onComplete || Prototype.emptyFunction; -this.options.onComplete = (function(transport, object) { -this.updateContent(); -onComplete(transport, object); -}).bind(this); -this.request(url); -}, -updateContent: function() { -var receiver = this.responseIsSuccess() ? -this.containers.success : this.containers.failure; -var response = this.transport.responseText; -if (!this.options.evalScripts) -response = response.stripScripts(); -if (receiver) { -if (this.options.insertion) { -new this.options.insertion(receiver, response); -} else { -Element.update(receiver, response); -} -} -if (this.responseIsSuccess()) { -if (this.onComplete) -setTimeout(this.onComplete.bind(this), 10); -} -} -}); -Ajax.PeriodicalUpdater = Class.create(); -Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), { -initialize: function(container, url, options) { -this.setOptions(options); -this.onComplete = this.options.onComplete; -this.frequency = (this.options.frequency || 2); -this.decay = (this.options.decay || 1); -this.updater = {}; -this.container = container; -this.url = url; -this.start(); -}, -start: function() { -this.options.onComplete = this.updateComplete.bind(this); -this.onTimerEvent(); -}, -stop: function() { -this.updater.onComplete = undefined; -clearTimeout(this.timer); -(this.onComplete || Prototype.emptyFunction).apply(this, arguments); -}, -updateComplete: function(request) { -if (this.options.decay) { -this.decay = (request.responseText == this.lastText ? -this.decay * this.options.decay : 1); -this.lastText = request.responseText; -} -this.timer = setTimeout(this.onTimerEvent.bind(this), -this.decay * this.frequency * 1000); -}, -onTimerEvent: function() { -this.updater = new Ajax.Updater(this.container, this.url, this.options); -} -}); -document.getElementsByClassName = function(className, parentElement) { -var children = ($(parentElement) || document.body).getElementsByTagName('*'); -return $A(children).inject([], function(elements, child) { -if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) -elements.push(child); -return elements; -}); -} -if (!window.Element) { -var Element = new Object(); -} -Object.extend(Element, { -visible: function(element) { -return $(element).style.display != 'none'; -}, -toggle: function() { -for (var i = 0; i < arguments.length; i++) { -var element = $(arguments[i]); -Element[Element.visible(element) ? 'hide' : 'show'](element); -} -}, -hide: function() { -for (var i = 0; i < arguments.length; i++) { -var element = $(arguments[i]); -element.style.display = 'none'; -} -}, -show: function() { -for (var i = 0; i < arguments.length; i++) { -var element = $(arguments[i]); -element.style.display = ''; -} -}, -remove: function(element) { -element = $(element); -element.parentNode.removeChild(element); -}, -update: function(element, html) { -$(element).innerHTML = html.stripScripts(); -setTimeout(function() {html.evalScripts()}, 10); -}, -getHeight: function(element) { -element = $(element); -return element.offsetHeight; -}, -classNames: function(element) { -return new Element.ClassNames(element); -}, -hasClassName: function(element, className) { -if (!(element = $(element))) return; -return Element.classNames(element).include(className); -}, -addClassName: function(element, className) { -if (!(element = $(element))) return; -return Element.classNames(element).add(className); -}, -removeClassName: function(element, className) { -if (!(element = $(element))) return; -return Element.classNames(element).remove(className); -}, -cleanWhitespace: function(element) { -element = $(element); -for (var i = 0; i < element.childNodes.length; i++) { -var node = element.childNodes[i]; -if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) -Element.remove(node); -} -}, -empty: function(element) { -return $(element).innerHTML.match(/^\s*$/); -}, -scrollTo: function(element) { -element = $(element); -var x = element.x ? element.x : element.offsetLeft, -y = element.y ? element.y : element.offsetTop; -window.scrollTo(x, y); -}, -getStyle: function(element, style) { -element = $(element); -var value = element.style[style.camelize()]; -if (!value) { -if (document.defaultView && document.defaultView.getComputedStyle) { -var css = document.defaultView.getComputedStyle(element, null); -value = css ? css.getPropertyValue(style) : null; -} else if (element.currentStyle) { -value = element.currentStyle[style.camelize()]; -} -} -if (window.opera && ['left', 'top', 'right', 'bottom'].include(style)) -if (Element.getStyle(element, 'position') == 'static') value = 'auto'; -return value == 'auto' ? null : value; -}, -setStyle: function(element, style) { -element = $(element); -for (name in style) -element.style[name.camelize()] = style[name]; -}, -getDimensions: function(element) { -element = $(element); -if (Element.getStyle(element, 'display') != 'none') -return {width: element.offsetWidth, height: element.offsetHeight}; -var els = element.style; -var originalVisibility = els.visibility; -var originalPosition = els.position; -els.visibility = 'hidden'; -els.position = 'absolute'; -els.display = ''; -var originalWidth = element.clientWidth; -var originalHeight = element.clientHeight; -els.display = 'none'; -els.position = originalPosition; -els.visibility = originalVisibility; -return {width: originalWidth, height: originalHeight}; -}, -makePositioned: function(element) { -element = $(element); -var pos = Element.getStyle(element, 'position'); -if (pos == 'static' || !pos) { -element._madePositioned = true; -element.style.position = 'relative'; -if (window.opera) { -element.style.top = 0; -element.style.left = 0; -} -} -}, -undoPositioned: function(element) { -element = $(element); -if (element._madePositioned) { -element._madePositioned = undefined; -element.style.position = -element.style.top = -element.style.left = -element.style.bottom = -element.style.right = ''; -} -}, -makeClipping: function(element) { -element = $(element); -if (element._overflow) return; -element._overflow = element.style.overflow; -if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden') -element.style.overflow = 'hidden'; -}, -undoClipping: function(element) { -element = $(element); -if (element._overflow) return; -element.style.overflow = element._overflow; -element._overflow = undefined; -} -}); -var Toggle = new Object(); -Toggle.display = Element.toggle; -Abstract.Insertion = function(adjacency) { -this.adjacency = adjacency; -} -Abstract.Insertion.prototype = { -initialize: function(element, content) { -this.element = $(element); -this.content = content.stripScripts(); -if (this.adjacency && this.element.insertAdjacentHTML) { -try { -this.element.insertAdjacentHTML(this.adjacency, this.content); -} catch (e) { -if (this.element.tagName.toLowerCase() == 'tbody') { -this.insertContent(this.contentFromAnonymousTable()); -} else { -throw e; -} -} -} else { -this.range = this.element.ownerDocument.createRange(); -if (this.initializeRange) this.initializeRange(); -this.insertContent([this.range.createContextualFragment(this.content)]); -} -setTimeout(function() {content.evalScripts()}, 10); -}, -contentFromAnonymousTable: function() { -var div = document.createElement('div'); -div.innerHTML = '' + this.content + '
'; -return $A(div.childNodes[0].childNodes[0].childNodes); -} -} -var Insertion = new Object(); -Insertion.Before = Class.create(); -Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), { -initializeRange: function() { -this.range.setStartBefore(this.element); -}, -insertContent: function(fragments) { -fragments.each((function(fragment) { -this.element.parentNode.insertBefore(fragment, this.element); -}).bind(this)); -} -}); -Insertion.Top = Class.create(); -Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), { -initializeRange: function() { -this.range.selectNodeContents(this.element); -this.range.collapse(true); -}, -insertContent: function(fragments) { -fragments.reverse(false).each((function(fragment) { -this.element.insertBefore(fragment, this.element.firstChild); -}).bind(this)); -} -}); -Insertion.Bottom = Class.create(); -Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), { -initializeRange: function() { -this.range.selectNodeContents(this.element); -this.range.collapse(this.element); -}, -insertContent: function(fragments) { -fragments.each((function(fragment) { -this.element.appendChild(fragment); -}).bind(this)); -} -}); -Insertion.After = Class.create(); -Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), { -initializeRange: function() { -this.range.setStartAfter(this.element); -}, -insertContent: function(fragments) { -fragments.each((function(fragment) { -this.element.parentNode.insertBefore(fragment, -this.element.nextSibling); -}).bind(this)); -} -}); -Element.ClassNames = Class.create(); -Element.ClassNames.prototype = { -initialize: function(element) { -this.element = $(element); -}, -_each: function(iterator) { -this.element.className.split(/\s+/).select(function(name) { -return name.length > 0; -})._each(iterator); -}, -set: function(className) { -this.element.className = className; -}, -add: function(classNameToAdd) { -if (this.include(classNameToAdd)) return; -this.set(this.toArray().concat(classNameToAdd).join(' ')); -}, -remove: function(classNameToRemove) { -if (!this.include(classNameToRemove)) return; -this.set(this.select(function(className) { -return className != classNameToRemove; -}).join(' ')); -}, -toString: function() { -return this.toArray().join(' '); -} -} -Object.extend(Element.ClassNames.prototype, Enumerable); -var Field = { -clear: function() { -for (var i = 0; i < arguments.length; i++) -$(arguments[i]).value = ''; -}, -focus: function(element) { -$(element).focus(); -}, -present: function() { -for (var i = 0; i < arguments.length; i++) -if ($(arguments[i]).value == '') return false; -return true; -}, -select: function(element) { -$(element).select(); -}, -activate: function(element) { -element = $(element); -element.focus(); -if (element.select) -element.select(); -} -} -var Form = { -serialize: function(form) { -var elements = Form.getElements($(form)); -var queryComponents = new Array(); -for (var i = 0; i < elements.length; i++) { -var queryComponent = Form.Element.serialize(elements[i]); -if (queryComponent) -queryComponents.push(queryComponent); -} -return queryComponents.join('&'); -}, -getElements: function(form) { -form = $(form); -var elements = new Array(); -for (tagName in Form.Element.Serializers) { -var tagElements = form.getElementsByTagName(tagName); -for (var j = 0; j < tagElements.length; j++) -elements.push(tagElements[j]); -} -return elements; -}, -getInputs: function(form, typeName, name) { -form = $(form); -var inputs = form.getElementsByTagName('input'); -if (!typeName && !name) -return inputs; -var matchingInputs = new Array(); -for (var i = 0; i < inputs.length; i++) { -var input = inputs[i]; -if ((typeName && input.type != typeName) || -(name && input.name != name)) -continue; -matchingInputs.push(input); -} -return matchingInputs; -}, -disable: function(form) { -var elements = Form.getElements(form); -for (var i = 0; i < elements.length; i++) { -var element = elements[i]; -element.blur(); -element.disabled = 'true'; -} -}, -enable: function(form) { -var elements = Form.getElements(form); -for (var i = 0; i < elements.length; i++) { -var element = elements[i]; -element.disabled = ''; -} -}, -findFirstElement: function(form) { -return Form.getElements(form).find(function(element) { -return element.type != 'hidden' && !element.disabled && -['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); -}); -}, -focusFirstElement: function(form) { -Field.activate(Form.findFirstElement(form)); -}, -reset: function(form) { -$(form).reset(); -} -} -Form.Element = { -serialize: function(element) { -element = $(element); -var method = element.tagName.toLowerCase(); -var parameter = Form.Element.Serializers[method](element); -if (parameter) { -var key = encodeURIComponent(parameter[0]); -if (key.length == 0) return; -if (parameter[1].constructor != Array) -parameter[1] = [parameter[1]]; -return parameter[1].map(function(value) { -return key + '=' + encodeURIComponent(value); -}).join('&'); -} -}, -getValue: function(element) { -element = $(element); -var method = element.tagName.toLowerCase(); -var parameter = Form.Element.Serializers[method](element); -if (parameter) -return parameter[1]; -} -} -Form.Element.Serializers = { -input: function(element) { -switch (element.type.toLowerCase()) { -case 'submit': -case 'hidden': -case 'password': -case 'text': -return Form.Element.Serializers.textarea(element); -case 'checkbox': -case 'radio': -return Form.Element.Serializers.inputSelector(element); -} -return false; -}, -inputSelector: function(element) { -if (element.checked) -return [element.name, element.value]; -}, -textarea: function(element) { -return [element.name, element.value]; -}, -select: function(element) { -return Form.Element.Serializers[element.type == 'select-one' ? -'selectOne' : 'selectMany'](element); -}, -selectOne: function(element) { -var value = '', opt, index = element.selectedIndex; -if (index >= 0) { -opt = element.options[index]; -value = opt.value; -if (!value && !('value' in opt)) -value = opt.text; -} -return [element.name, value]; -}, -selectMany: function(element) { -var value = new Array(); -for (var i = 0; i < element.length; i++) { -var opt = element.options[i]; -if (opt.selected) { -var optValue = opt.value; -if (!optValue && !('value' in opt)) -optValue = opt.text; -value.push(optValue); -} -} -return [element.name, value]; -} -} -var $F = Form.Element.getValue; -Abstract.TimedObserver = function() {} -Abstract.TimedObserver.prototype = { -initialize: function(element, frequency, callback) { -this.frequency = frequency; -this.element = $(element); -this.callback = callback; -this.lastValue = this.getValue(); -this.registerCallback(); -}, -registerCallback: function() { -setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); -}, -onTimerEvent: function() { -var value = this.getValue(); -if (this.lastValue != value) { -this.callback(this.element, value); -this.lastValue = value; -} -} -} -Form.Element.Observer = Class.create(); -Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { -getValue: function() { -return Form.Element.getValue(this.element); -} -}); -Form.Observer = Class.create(); -Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { -getValue: function() { -return Form.serialize(this.element); -} -}); -Abstract.EventObserver = function() {} -Abstract.EventObserver.prototype = { -initialize: function(element, callback) { -this.element = $(element); -this.callback = callback; -this.lastValue = this.getValue(); -if (this.element.tagName.toLowerCase() == 'form') -this.registerFormCallbacks(); -else -this.registerCallback(this.element); -}, -onElementEvent: function() { -var value = this.getValue(); -if (this.lastValue != value) { -this.callback(this.element, value); -this.lastValue = value; -} -}, -registerFormCallbacks: function() { -var elements = Form.getElements(this.element); -for (var i = 0; i < elements.length; i++) -this.registerCallback(elements[i]); -}, -registerCallback: function(element) { -if (element.type) { -switch (element.type.toLowerCase()) { -case 'checkbox': -case 'radio': -Event.observe(element, 'click', this.onElementEvent.bind(this)); -break; -case 'password': -case 'text': -case 'textarea': -case 'select-one': -case 'select-multiple': -Event.observe(element, 'change', this.onElementEvent.bind(this)); -break; -} -} -} -} -Form.Element.EventObserver = Class.create(); -Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { -getValue: function() { -return Form.Element.getValue(this.element); -} -}); -Form.EventObserver = Class.create(); -Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { -getValue: function() { -return Form.serialize(this.element); -} -}); -if (!window.Event) { -var Event = new Object(); -} -Object.extend(Event, { -KEY_BACKSPACE: 8, -KEY_TAB: 9, -KEY_RETURN: 13, -KEY_ESC: 27, -KEY_LEFT: 37, -KEY_UP: 38, -KEY_RIGHT: 39, -KEY_DOWN: 40, -KEY_DELETE: 46, -element: function(event) { -return event.target || event.srcElement; -}, -isLeftClick: function(event) { -return (((event.which) && (event.which == 1)) || -((event.button) && (event.button == 1))); -}, -pointerX: function(event) { -return event.pageX || (event.clientX + -(document.documentElement.scrollLeft || document.body.scrollLeft)); -}, -pointerY: function(event) { -return event.pageY || (event.clientY + -(document.documentElement.scrollTop || document.body.scrollTop)); -}, -stop: function(event) { -if (event.preventDefault) { -event.preventDefault(); -event.stopPropagation(); -} else { -event.returnValue = false; -event.cancelBubble = true; -} -}, -findElement: function(event, tagName) { -var element = Event.element(event); -while (element.parentNode && (!element.tagName || -(element.tagName.toUpperCase() != tagName.toUpperCase()))) -element = element.parentNode; -return element; -}, -observers: false, -_observeAndCache: function(element, name, observer, useCapture) { -if (!this.observers) this.observers = []; -if (element.addEventListener) { -this.observers.push([element, name, observer, useCapture]); -element.addEventListener(name, observer, useCapture); -} else if (element.attachEvent) { -this.observers.push([element, name, observer, useCapture]); -element.attachEvent('on' + name, observer); -} -}, -unloadCache: function() { -if (!Event.observers) return; -for (var i = 0; i < Event.observers.length; i++) { -Event.stopObserving.apply(this, Event.observers[i]); -Event.observers[i][0] = null; -} -Event.observers = false; -}, -observe: function(element, name, observer, useCapture) { -var element = $(element); -useCapture = useCapture || false; -if (name == 'keypress' && -(navigator.appVersion.match(/Konqueror|Safari|KHTML/) -|| element.attachEvent)) -name = 'keydown'; -this._observeAndCache(element, name, observer, useCapture); -}, -stopObserving: function(element, name, observer, useCapture) { -var element = $(element); -useCapture = useCapture || false; -if (name == 'keypress' && -(navigator.appVersion.match(/Konqueror|Safari|KHTML/) -|| element.detachEvent)) -name = 'keydown'; -if (element.removeEventListener) { -element.removeEventListener(name, observer, useCapture); -} else if (element.detachEvent) { -element.detachEvent('on' + name, observer); -} -} -}); -Event.observe(window, 'unload', Event.unloadCache, false); -var Position = { -includeScrollOffsets: false, -prepare: function() { -this.deltaX = window.pageXOffset -|| document.documentElement.scrollLeft -|| document.body.scrollLeft -|| 0; -this.deltaY = window.pageYOffset -|| document.documentElement.scrollTop -|| document.body.scrollTop -|| 0; -}, -realOffset: function(element) { -var valueT = 0, valueL = 0; -do { -valueT += element.scrollTop || 0; -valueL += element.scrollLeft || 0; -element = element.parentNode; -} while (element); -return [valueL, valueT]; -}, -cumulativeOffset: function(element) { -var valueT = 0, valueL = 0; -do { -valueT += element.offsetTop || 0; -valueL += element.offsetLeft || 0; -element = element.offsetParent; -} while (element); -return [valueL, valueT]; -}, -positionedOffset: function(element) { -var valueT = 0, valueL = 0; -do { -valueT += element.offsetTop || 0; -valueL += element.offsetLeft || 0; -element = element.offsetParent; -if (element) { -p = Element.getStyle(element, 'position'); -if (p == 'relative' || p == 'absolute') break; -} -} while (element); -return [valueL, valueT]; -}, -offsetParent: function(element) { -if (element.offsetParent) return element.offsetParent; -if (element == document.body) return element; -while ((element = element.parentNode) && element != document.body) -if (Element.getStyle(element, 'position') != 'static') -return element; -return document.body; -}, -within: function(element, x, y) { -if (this.includeScrollOffsets) -return this.withinIncludingScrolloffsets(element, x, y); -this.xcomp = x; -this.ycomp = y; -this.offset = this.cumulativeOffset(element); -return (y >= this.offset[1] && -y < this.offset[1] + element.offsetHeight && -x >= this.offset[0] && -x < this.offset[0] + element.offsetWidth); -}, -withinIncludingScrolloffsets: function(element, x, y) { -var offsetcache = this.realOffset(element); -this.xcomp = x + offsetcache[0] - this.deltaX; -this.ycomp = y + offsetcache[1] - this.deltaY; -this.offset = this.cumulativeOffset(element); -return (this.ycomp >= this.offset[1] && -this.ycomp < this.offset[1] + element.offsetHeight && -this.xcomp >= this.offset[0] && -this.xcomp < this.offset[0] + element.offsetWidth); -}, -overlap: function(mode, element) { -if (!mode) return 0; -if (mode == 'vertical') -return ((this.offset[1] + element.offsetHeight) - this.ycomp) / -element.offsetHeight; -if (mode == 'horizontal') -return ((this.offset[0] + element.offsetWidth) - this.xcomp) / -element.offsetWidth; -}, -clone: function(source, target) { -source = $(source); -target = $(target); -target.style.position = 'absolute'; -var offsets = this.cumulativeOffset(source); -target.style.top = offsets[1] + 'px'; -target.style.left = offsets[0] + 'px'; -target.style.width = source.offsetWidth + 'px'; -target.style.height = source.offsetHeight + 'px'; -}, -page: function(forElement) { -var valueT = 0, valueL = 0; -var element = forElement; -do { -valueT += element.offsetTop || 0; -valueL += element.offsetLeft || 0; -if (element.offsetParent==document.body) -if (Element.getStyle(element,'position')=='absolute') break; -} while (element = element.offsetParent); -element = forElement; -do { -valueT -= element.scrollTop || 0; -valueL -= element.scrollLeft || 0; -} while (element = element.parentNode); -return [valueL, valueT]; -}, -clone: function(source, target) { -var options = Object.extend({ -setLeft: true, -setTop: true, -setWidth: true, -setHeight: true, -offsetTop: 0, -offsetLeft: 0 -}, arguments[2] || {}) -source = $(source); -var p = Position.page(source); -target = $(target); -var delta = [0, 0]; -var parent = null; -if (Element.getStyle(target,'position') == 'absolute') { -parent = Position.offsetParent(target); -delta = Position.page(parent); -} -if (parent == document.body) { -delta[0] -= document.body.offsetLeft; -delta[1] -= document.body.offsetTop; -} -if(options.setLeft) target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; -if(options.setTop) target.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; -if(options.setWidth) target.style.width = source.offsetWidth + 'px'; -if(options.setHeight) target.style.height = source.offsetHeight + 'px'; -}, -absolutize: function(element) { -element = $(element); -if (element.style.position == 'absolute') return; -Position.prepare(); -var offsets = Position.positionedOffset(element); -var top = offsets[1]; -var left = offsets[0]; -var width = element.clientWidth; -var height = element.clientHeight; -element._originalLeft = left - parseFloat(element.style.left || 0); -element._originalTop = top - parseFloat(element.style.top || 0); -element._originalWidth = element.style.width; -element._originalHeight = element.style.height; -element.style.position = 'absolute'; -element.style.top = top + 'px';; -element.style.left = left + 'px';; -element.style.width = width + 'px';; -element.style.height = height + 'px';; -}, -relativize: function(element) { -element = $(element); -if (element.style.position == 'relative') return; -Position.prepare(); -element.style.position = 'relative'; -var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); -var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); -element.style.top = top + 'px'; -element.style.left = left + 'px'; -element.style.height = element._originalHeight; -element.style.width = element._originalWidth; -} -} -if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) { -Position.cumulativeOffset = function(element) { -var valueT = 0, valueL = 0; -do { -valueT += element.offsetTop || 0; -valueL += element.offsetLeft || 0; -if (element.offsetParent == document.body) -if (Element.getStyle(element, 'position') == 'absolute') break; -element = element.offsetParent; -} while (element); -return [valueL, valueT]; -} -} diff --git a/test/expected_dir/js1.js/javascript/comment b/test/expected_dir/js1.js/javascript/comment deleted file mode 100644 index 71f7f83..0000000 --- a/test/expected_dir/js1.js/javascript/comment +++ /dev/null @@ -1,46 +0,0 @@ -/* Prototype JavaScript framework, version 1.4.0 -* (c) 2005 Sam Stephenson -* -* Prototype is freely distributable under the terms of an MIT-style license. -* For details, see the Prototype web site: http://prototype.conio.net/ -* -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/* Force "Connection: close" for Mozilla browsers to work around -* a bug where XMLHttpReqeuest sends an incorrect Content-length -* header. See Mozilla Bugzilla #246651. -*/ -/* Avoid memory leak in MSIE: clean up the oncomplete event handler */ -/*--------------------------------------------------------------------------*/ -// removes whitespace-only text node children -// All *Width and *Height properties give 0 on elements with display none, -// so enable the element temporarily -// Opera returns the offset relative to the positioning context, when an -// element is position relative but top and left have not been defined -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -// find the first node with the given tagName, starting from the -// node the event was triggered on; traverses the DOM upwards -/* prevent memory leaks in IE */ -// set to true if needed, warning: firefox performance problems -// NOT neeeded for page scrolling, only if draggable contained in -// scrollable elements -// must be called before calling withinIncludingScrolloffset, every time the -// page is scrolled -// caches x/y coordinate pair to use with overlap -// within must be called directly before -// Safari fix -// find page position of source -// find coordinate system to use -// delta [0,0] will do fine with position: fixed elements, -// position:absolute needs offsetParent deltas -// correct by body offsets (fixes Safari) -// set position -// Safari returns margins on body which is incorrect if the child is absolutely -// positioned. For performance reasons, redefine Position.cumulativeOffset for -// KHTML/WebKit only. diff --git a/test/expected_dir/js2.js b/test/expected_dir/js2.js new file mode 100644 index 0000000..48019a4 --- /dev/null +++ b/test/expected_dir/js2.js @@ -0,0 +1,13 @@ +javascript code diff --git a/test/expected_dir/js2.js/javascript/code b/test/expected_dir/js2.js/javascript/code deleted file mode 100644 index 2b8e7c5..0000000 --- a/test/expected_dir/js2.js/javascript/code +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/test/expected_dir/js2.js/javascript/comment b/test/expected_dir/js2.js/javascript/comment deleted file mode 100644 index 636c0ba..0000000 --- a/test/expected_dir/js2.js/javascript/comment +++ /dev/null @@ -1,7 +0,0 @@ -/* -Random Comments -Foo Foo Foo -*/ -// comment -// another comment -//Set delay before submenu disappears after mouse moves out of it (in milliseconds) diff --git a/test/expected_dir/js3.js b/test/expected_dir/js3.js new file mode 100644 index 0000000..ed52700 --- /dev/null +++ b/test/expected_dir/js3.js @@ -0,0 +1,2 @@ +javascript code return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'"; +javascript comment // comment diff --git a/test/expected_dir/jsp1.jsp b/test/expected_dir/jsp1.jsp new file mode 100644 index 0000000..6ba6c49 --- /dev/null +++ b/test/expected_dir/jsp1.jsp @@ -0,0 +1,14 @@ +html code +html code +html code JSP page +html code +html code +java code <%@ page language="java" %> +java code <% out.println("Hello World"); %> +java comment <% // comment +java comment /* +java comment * more comment +java comment */ +html code %> +html code +html code diff --git a/test/expected_dir/jsp1.jsp/html/code b/test/expected_dir/jsp1.jsp/html/code deleted file mode 100644 index c34bf15..0000000 --- a/test/expected_dir/jsp1.jsp/html/code +++ /dev/null @@ -1,8 +0,0 @@ - - -JSP page - - -%> - - diff --git a/test/expected_dir/jsp1.jsp/java/blanks b/test/expected_dir/jsp1.jsp/java/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/jsp1.jsp/java/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/jsp1.jsp/java/code b/test/expected_dir/jsp1.jsp/java/code deleted file mode 100644 index e139ba9..0000000 --- a/test/expected_dir/jsp1.jsp/java/code +++ /dev/null @@ -1,2 +0,0 @@ -<%@ page language="java" %> -<% out.println("Hello World"); %> diff --git a/test/expected_dir/jsp1.jsp/java/comment b/test/expected_dir/jsp1.jsp/java/comment deleted file mode 100644 index 49d6ff4..0000000 --- a/test/expected_dir/jsp1.jsp/java/comment +++ /dev/null @@ -1,4 +0,0 @@ -<% // comment -/* -* more comment -*/ diff --git a/test/expected_dir/limbo.b b/test/expected_dir/limbo.b new file mode 100644 index 0000000..c76e9ea --- /dev/null +++ b/test/expected_dir/limbo.b @@ -0,0 +1,65 @@ +limbo code implement HgReadrevlog; +limbo blank +limbo code include "sys.m"; +limbo code sys: Sys; +limbo code sprint: import sys; +limbo code include "draw.m"; +limbo code include "arg.m"; +limbo code include "string.m"; +limbo code str: String; +limbo code include "mercurial.m"; +limbo code mercurial: Mercurial; +limbo code Revlog, Repo, Entry, Nodeid, Change: import mercurial; +limbo blank +limbo code dflag: int; +limbo blank +limbo code HgReadrevlog: module { +limbo code init: fn(nil: ref Draw->Context, args: list of string); +limbo code }; +limbo blank +limbo code init(nil: ref Draw->Context, args: list of string) +limbo code { +limbo code sys = load Sys Sys->PATH; +limbo code arg := load Arg Arg->PATH; +limbo code str = load String String->PATH; +limbo code mercurial = load Mercurial Mercurial->PATH; +limbo code mercurial->init(); +limbo blank +limbo code arg->init(args); +limbo code arg->setusage(arg->progname()+" [-d] path"); +limbo code while((c := arg->opt()) != 0) +limbo code case c { +limbo code 'd' => dflag++; +limbo code if(dflag > 1) +limbo code mercurial->debug++; +limbo code * => arg->usage(); +limbo code } +limbo code args = arg->argv(); +limbo code if(len args != 1) +limbo code arg->usage(); +limbo code path := hd args; +limbo blank +limbo code (rl, err) := Revlog.open(path); +limbo code if(err != nil) +limbo code fail(err); +limbo blank +limbo code last: int; +limbo code (last, err) = rl.lastrev(); +limbo code if(err != nil) +limbo code fail(err); +limbo blank +limbo code e: ref Entry; +limbo code for(i := 0; i <= last; i++) { +limbo code (e, err) = rl.findrev(i); +limbo code if(err != nil) +limbo code fail(err); +limbo comment #sys->print("entry %d:\n", i); +limbo code sys->print("%s\n", e.text()); +limbo code } +limbo code } +limbo blank +limbo code fail(s: string) +limbo code { +limbo code sys->fprint(sys->fildes(2), "%s\n", s); +limbo code raise "fail:"+s; +limbo code } diff --git a/test/expected_dir/limbo.m b/test/expected_dir/limbo.m new file mode 100644 index 0000000..ae490fa --- /dev/null +++ b/test/expected_dir/limbo.m @@ -0,0 +1,8 @@ +limbo code Htmlent: module { +limbo code PATH: con "/dis/lib/htmlent.dis"; +limbo code entities: array of (string, int); +limbo blank +limbo code init: fn(); +limbo code lookup: fn(name: string): int; +limbo code conv: fn(s: string): string; +limbo code }; diff --git a/test/expected_dir/logtalk.lgt b/test/expected_dir/logtalk.lgt new file mode 100644 index 0000000..9f30fe1 --- /dev/null +++ b/test/expected_dir/logtalk.lgt @@ -0,0 +1,11 @@ +logtalk comment /* test file for Logtalk parsing */ +logtalk blank +logtalk comment % this is a Logtalk source file +logtalk blank +logtalk code :- object(hello_world). +logtalk blank +logtalk comment % the initialization/1 directive argument is automatically executed +logtalk comment % when the object is loaded into memory: +logtalk code :- initialization((nl, write('********** Hello World! **********'), nl)). +logtalk blank +logtalk code :- end_object. diff --git a/test/expected_dir/lsp1.lsp b/test/expected_dir/lsp1.lsp new file mode 100644 index 0000000..7bfd739 --- /dev/null +++ b/test/expected_dir/lsp1.lsp @@ -0,0 +1,135 @@ +lisp comment ;;; CrapsSim.lsp +lisp blank +lisp comment """ +lisp comment The main purpose of this program was to implement a Craps game, using a language that we have just +lisp comment learned. Also, it was written in a functional style with almost no reliance on the assignment +lisp comment operation. Only one local variable called THROW was used. +lisp comment """ +lisp blank +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp comment ;;; ======================================= CRAPS SIMULATION ============================================= ;;; +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp blank +lisp comment ;;; ** This function takes no parameters as input and returns a random number between 1 and 6. ** +lisp blank +lisp code (DEFUN THROW-DIE () +lisp code (+ (RANDOM 6) 1) ;;; get a random number between 0 and 5 and then add 1 +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes no parameters as input and returns a LIST with two numbers between 1 and 6. ** +lisp blank +lisp blank +lisp code (DEFUN THROW-DICE () +lisp blank +lisp code (LIST (THROW-DIE) (THROW-DIE)) ;;; create a list with two random numbers +lisp blank +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if both +lisp comment ;;; numbers are equal to 6. Nil is returned otherwise. ** +lisp blank +lisp code (DEFUN BOXCARS-P (A B) +lisp code (AND (EQUAL '6 A) +lisp code (EQUAL '6 B) +lisp code ) +lisp blank +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if both +lisp comment ;;; numbers are equal to 1. Nil is returned otherwise. ** +lisp blank +lisp code (DEFUN SNAKE-EYES-P (A B) +lisp code (AND (EQUAL '1 A) +lisp code (EQUAL '1 B) +lisp code ) +lisp blank +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if the +lisp comment ;;; sum of both numbers is equal to a 7 or 11. Nil is returned otherwise. ** +lisp blank +lisp code (DEFUN INSTANT-WIN-P (A B) +lisp code (OR (EQUAL '7 (+ A B)) +lisp code (EQUAL '11 (+ A B)) +lisp code ) +lisp blank +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if the +lisp comment ;;; sum of both numbers is equal to a 2, 3 or 12. Nil is returned otherwise. ** +lisp blank +lisp code (DEFUN INSTANT-LOSS-P (A B) +lisp code (OR (EQUAL '2 (+ A B)) +lisp code (EQUAL '3 (+ A B)) +lisp code (EQUAL '12 (+ A B)) +lisp code ) +lisp blank +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This function takes two numbers as parameters for input and returns a string. If function BOXCARS_P +lisp comment ;;; returns T, then the returned string equals BOXCARS. If function SNAKE_EYES_P returns T, then the +lisp comment ;;; returned string equals SNAKE_EYES. The string contains Nil otherwise. ** +lisp blank +lisp code (DEFUN SAY-THROW (A B) +lisp code (COND ((BOXCARS-P A B) 'BOXCARS) ;;; make use of function BOXCARS_P +lisp code ((SNAKE-EYES-P A B) 'SNAKE-EYES) ;;; make use of function SNAKE_EYES_P +lisp blank +lisp code ) +lisp code ) +lisp blank +lisp comment ;;; ====================================================================================================== ;;; +lisp blank +lisp comment ;;; ** This is the main function used to simulate the game of craps. Variable THROW contains a LIST of two +lisp comment ;;; numbers between 1 and 6. The numbers located in THROW, are used as parameters for the other functions. +lisp comment ;;; The several pieces used for output are listed together and then the LIST is returned from this +lisp comment ;;; function. +lisp blank +lisp blank +lisp code (DEFUN CRAPS () +lisp code (LET THROW (THROW-DICE)) ;;; get initial roll of the dice +lisp blank +lisp comment ;;; if roll is a win, then LIST the appropriate output +lisp blank +lisp code (COND ((INSTANT-WIN-P (FIRST THROW) (SECOND THROW)) +lisp code (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'WIN)) +lisp blank +lisp comment ;;; if roll is a loss, then check for BOXCARS or SNAKE-EYES +lisp blank +lisp code ((INSTANT-LOSS-P (FIRST THROW) (SECOND THROW)) +lisp blank +lisp code (IF (EQUAL 'NIL (SAY-THROW (FIRST THROW) (SECOND THROW))) ;;; if Nil then LIST appropriate output +lisp blank +lisp code (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'LOSE) +lisp blank +lisp comment ;;; else include the BOXCARS or SNAKE-EYES string in the output +lisp blank +lisp code (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (SAY-THROW (FIRST THROW) (SECOND THROW)) +lisp code '-- 'YOU 'LOSE))) +lisp blank +lisp comment ;;; if roll is not instant win or loss then output sum of dice +lisp blank +lisp code (T (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- 'YOUR 'POINT 'IS (+ (FIRST THROW) +lisp code (SECOND THROW)))) +lisp code ) ;;; end COND +lisp blank +lisp code ) ;;; end LET +lisp blank +lisp blank +lisp code ) +lisp blank +lisp blank +lisp comment ;;; ======================================== END OF PROGRAM CRAPS ======================================== ;;; diff --git a/test/expected_dir/lsp1.lsp/lisp/blanks b/test/expected_dir/lsp1.lsp/lisp/blanks deleted file mode 100644 index 7003e7f..0000000 --- a/test/expected_dir/lsp1.lsp/lisp/blanks +++ /dev/null @@ -1 +0,0 @@ -51 \ No newline at end of file diff --git a/test/expected_dir/lsp1.lsp/lisp/code b/test/expected_dir/lsp1.lsp/lisp/code deleted file mode 100644 index b79eef4..0000000 --- a/test/expected_dir/lsp1.lsp/lisp/code +++ /dev/null @@ -1,46 +0,0 @@ -(DEFUN THROW-DIE () -(+ (RANDOM 6) 1) ;;; get a random number between 0 and 5 and then add 1 -) -(DEFUN THROW-DICE () -(LIST (THROW-DIE) (THROW-DIE)) ;;; create a list with two random numbers -) -(DEFUN BOXCARS-P (A B) -(AND (EQUAL '6 A) -(EQUAL '6 B) -) -) -(DEFUN SNAKE-EYES-P (A B) -(AND (EQUAL '1 A) -(EQUAL '1 B) -) -) -(DEFUN INSTANT-WIN-P (A B) -(OR (EQUAL '7 (+ A B)) -(EQUAL '11 (+ A B)) -) -) -(DEFUN INSTANT-LOSS-P (A B) -(OR (EQUAL '2 (+ A B)) -(EQUAL '3 (+ A B)) -(EQUAL '12 (+ A B)) -) -) -(DEFUN SAY-THROW (A B) -(COND ((BOXCARS-P A B) 'BOXCARS) ;;; make use of function BOXCARS_P -((SNAKE-EYES-P A B) 'SNAKE-EYES) ;;; make use of function SNAKE_EYES_P -) -) -(DEFUN CRAPS () -(LET THROW (THROW-DICE)) ;;; get initial roll of the dice -(COND ((INSTANT-WIN-P (FIRST THROW) (SECOND THROW)) -(LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'WIN)) -((INSTANT-LOSS-P (FIRST THROW) (SECOND THROW)) -(IF (EQUAL 'NIL (SAY-THROW (FIRST THROW) (SECOND THROW))) ;;; if Nil then LIST appropriate output -(LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'LOSE) -(LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (SAY-THROW (FIRST THROW) (SECOND THROW)) -'-- 'YOU 'LOSE))) -(T (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- 'YOUR 'POINT 'IS (+ (FIRST THROW) -(SECOND THROW)))) -) ;;; end COND -) ;;; end LET -) diff --git a/test/expected_dir/lsp1.lsp/lisp/comment b/test/expected_dir/lsp1.lsp/lisp/comment deleted file mode 100644 index 4e7403d..0000000 --- a/test/expected_dir/lsp1.lsp/lisp/comment +++ /dev/null @@ -1,38 +0,0 @@ -;;; CrapsSim.lsp -""" -The main purpose of this program was to implement a Craps game, using a language that we have just -learned. Also, it was written in a functional style with almost no reliance on the assignment -operation. Only one local variable called THROW was used. -""" -;;; ====================================================================================================== ;;; -;;; ======================================= CRAPS SIMULATION ============================================= ;;; -;;; ====================================================================================================== ;;; -;;; ** This function takes no parameters as input and returns a random number between 1 and 6. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes no parameters as input and returns a LIST with two numbers between 1 and 6. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if both -;;; numbers are equal to 6. Nil is returned otherwise. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if both -;;; numbers are equal to 1. Nil is returned otherwise. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if the -;;; sum of both numbers is equal to a 7 or 11. Nil is returned otherwise. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes two numbers as parameters for input and returns T or Nil. T is returned if the -;;; sum of both numbers is equal to a 2, 3 or 12. Nil is returned otherwise. ** -;;; ====================================================================================================== ;;; -;;; ** This function takes two numbers as parameters for input and returns a string. If function BOXCARS_P -;;; returns T, then the returned string equals BOXCARS. If function SNAKE_EYES_P returns T, then the -;;; returned string equals SNAKE_EYES. The string contains Nil otherwise. ** -;;; ====================================================================================================== ;;; -;;; ** This is the main function used to simulate the game of craps. Variable THROW contains a LIST of two -;;; numbers between 1 and 6. The numbers located in THROW, are used as parameters for the other functions. -;;; The several pieces used for output are listed together and then the LIST is returned from this -;;; function. -;;; if roll is a win, then LIST the appropriate output -;;; if roll is a loss, then check for BOXCARS or SNAKE-EYES -;;; else include the BOXCARS or SNAKE-EYES string in the output -;;; if roll is not instant win or loss then output sum of dice -;;; ======================================== END OF PROGRAM CRAPS ======================================== ;;; diff --git a/test/expected_dir/lua1.lua b/test/expected_dir/lua1.lua new file mode 100644 index 0000000..92ba5d7 --- /dev/null +++ b/test/expected_dir/lua1.lua @@ -0,0 +1,121 @@ +lua comment -- random code from http://lua-users.org/wiki/TextJustification +lua comment -- easy queue implementation ------------------------------------------ +lua blank +lua code function q_create() +lua code local q = {} +lua code q.first = 0 +lua code q.last = 0 +lua code return q +lua code end +lua blank +lua code function q_insert(q, s) +lua code q[q.last] = s +lua code q.last = q.last + 1 +lua code end +lua blank +lua code function q_empty(q) +lua code return q.first >= q.last +lua code end +lua blank +lua code function q_remove(q) +lua code if q_empty(q) then +lua code return nil +lua code end +lua code local s = q[q.first] +lua code q[q.first] = nil +lua code q.first = q.first+1 +lua code return s +lua code end +lua blank +lua code function q_card(q) +lua code return q.last - q.first +lua code end +lua blank +lua code function q_length(q, f) +lua code local l, i = 0, q.first +lua code while i < q.last do +lua code l = l + strlen(q[i]) +lua code i = i + 1 +lua code end +lua code return l +lua code end +lua blank +lua comment -- line creation routines ------------------------------------------ +lua blank +lua comment -- justifies one line to fit into MAX columns +lua code function justify(q) +lua code local blanks = MAX - q_length(q) +lua code local skips = q_card(q) - 1 +lua code local line = q_remove(q) +lua code local quotient = floor(blanks/skips) +lua code local reminder = blanks/skips - quotient +lua code local error = 0 +lua code while skips > 0 do +lua code error = error + reminder +lua code if error >= 0.5 then +lua code error = error - 1 +lua code line = line .. strrep(" ", quotient+1) +lua code else +lua code line = line .. strrep(" ", quotient) +lua code end +lua code line = line .. q_remove(q) +lua code skips = skips - 1 +lua code end +lua code return line or "" +lua code end +lua blank +lua comment -- join all words with one space between them +lua code function catenate(q) +lua code local line = q_remove(q) +lua code while not q_empty(q) do +lua code line = line .. " " .. q_remove(q) +lua code end +lua code return line or "" +lua code end +lua blank +lua comment -- main program ----------------------------------------------------- +lua code DEFMAX = 72 +lua comment -- tries to get MAX from command-line +lua code if not arg or getn(arg) < 1 then +lua code MAX = DEFMAX +lua code else +lua code MAX = tonumber(arg[1]) +lua code if not MAX or MAX < 0 then +lua code MAX = DEFMAX +lua code end +lua code end +lua blank +lua comment -- collects all text from stdin +lua code text = q_create() +lua code line = read() +lua code while line do +lua code _, n = gsub(line, "(%S+)", function (s) q_insert(%text, s) end) +lua code if n == 0 then +lua code q_insert(text, "\n") +lua code end +lua code line = read() +lua code end +lua blank +lua comment -- justify paragraphs +lua code line = q_create() +lua code word = q_remove(text) +lua code size = 0 +lua code while word do +lua code if word == "\n" then +lua code if not q_empty(line) then +lua code write(catenate(line), "\n\n") +lua code else +lua code write("\n") +lua code end +lua code size = 0 +lua code elseif size + strlen(word) > MAX then +lua code write(justify(line), "\n") +lua code size = 0 +lua code end +lua code if word ~= "\n" then +lua code q_insert(line, word) +lua code size = size + strlen(word) + 1 +lua code end +lua code word = q_remove(text) +lua code end +lua code write(catenate(line), "\n") diff --git a/test/expected_dir/lua1.lua/lua/blanks b/test/expected_dir/lua1.lua/lua/blanks deleted file mode 100644 index 3cacc0b..0000000 --- a/test/expected_dir/lua1.lua/lua/blanks +++ /dev/null @@ -1 +0,0 @@ -12 \ No newline at end of file diff --git a/test/expected_dir/lua1.lua/lua/code b/test/expected_dir/lua1.lua/lua/code deleted file mode 100644 index 32b5ead..0000000 --- a/test/expected_dir/lua1.lua/lua/code +++ /dev/null @@ -1,100 +0,0 @@ -function q_create() -local q = {} -q.first = 0 -q.last = 0 -return q -end -function q_insert(q, s) -q[q.last] = s -q.last = q.last + 1 -end -function q_empty(q) -return q.first >= q.last -end -function q_remove(q) -if q_empty(q) then -return nil -end -local s = q[q.first] -q[q.first] = nil -q.first = q.first+1 -return s -end -function q_card(q) -return q.last - q.first -end -function q_length(q, f) -local l, i = 0, q.first -while i < q.last do -l = l + strlen(q[i]) -i = i + 1 -end -return l -end -function justify(q) -local blanks = MAX - q_length(q) -local skips = q_card(q) - 1 -local line = q_remove(q) -local quotient = floor(blanks/skips) -local reminder = blanks/skips - quotient -local error = 0 -while skips > 0 do -error = error + reminder -if error >= 0.5 then -error = error - 1 -line = line .. strrep(" ", quotient+1) -else -line = line .. strrep(" ", quotient) -end -line = line .. q_remove(q) -skips = skips - 1 -end -return line or "" -end -function catenate(q) -local line = q_remove(q) -while not q_empty(q) do -line = line .. " " .. q_remove(q) -end -return line or "" -end -DEFMAX = 72 -if not arg or getn(arg) < 1 then -MAX = DEFMAX -else -MAX = tonumber(arg[1]) -if not MAX or MAX < 0 then -MAX = DEFMAX -end -end -text = q_create() -line = read() -while line do -_, n = gsub(line, "(%S+)", function (s) q_insert(%text, s) end) -if n == 0 then -q_insert(text, "\n") -end -line = read() -end -line = q_create() -word = q_remove(text) -size = 0 -while word do -if word == "\n" then -if not q_empty(line) then -write(catenate(line), "\n\n") -else -write("\n") -end -size = 0 -elseif size + strlen(word) > MAX then -write(justify(line), "\n") -size = 0 -end -if word ~= "\n" then -q_insert(line, word) -size = size + strlen(word) + 1 -end -word = q_remove(text) -end -write(catenate(line), "\n") diff --git a/test/expected_dir/lua1.lua/lua/comment b/test/expected_dir/lua1.lua/lua/comment deleted file mode 100644 index 7f5dbe6..0000000 --- a/test/expected_dir/lua1.lua/lua/comment +++ /dev/null @@ -1,9 +0,0 @@ --- random code from http://lua-users.org/wiki/TextJustification --- easy queue implementation ------------------------------------------ --- line creation routines ------------------------------------------ --- justifies one line to fit into MAX columns --- join all words with one space between them --- main program ----------------------------------------------------- --- tries to get MAX from command-line --- collects all text from stdin --- justify paragraphs diff --git a/test/expected_dir/mathematica1.m b/test/expected_dir/mathematica1.m new file mode 100644 index 0000000..ea293c3 --- /dev/null +++ b/test/expected_dir/mathematica1.m @@ -0,0 +1,1480 @@ +mathematica blank +mathematica code SetEnhancedTimes[False]; +mathematica code SetSourceLanguage["C"]; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Options *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code createCode[derivOrder_, useJacobian_, splitUpwindDerivs_, useVectors_, useOpenCL_, evolutionTimelevels_, addMatter_, formulation_] := +mathematica code Module[{prefix, suffix, thorn}, +mathematica blank +mathematica code prefix = "ML_"; +mathematica code suffix = +mathematica code "" +mathematica code <> If [useJacobian, "_MP", ""] +mathematica code <> If [derivOrder!=4, "_O" <> ToString[derivOrder], ""] +mathematica code <> If [splitUpwindDerivs, "", "_UPW"] +mathematica code <> If [useVectors, "", "_NV"] +mathematica code <> If [useOpenCL, "_CL", ""] +mathematica comment (* <> If [evolutionTimelevels!=3, "_TL" <> ToString[evolutionTimelevels], ""] *) +mathematica comment (* <> If [addMatter==1, "_M", ""] *) +mathematica code ; +mathematica blank +mathematica code thorn = prefix <> formulation <> suffix; +mathematica blank +mathematica code SetAttributes[IfCCZ4, HoldAll]; +mathematica code IfCCZ4[expr_, else_:Sequence[]] := If[formulation === "CCZ4", expr, Unevaluated[else]]; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Derivatives *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code KD = KroneckerDelta; +mathematica blank +mathematica code derivatives = +mathematica code { +mathematica code PDstandardNth[i_] -> StandardCenteredDifferenceOperator[1,fdOrder/2,i], +mathematica code PDstandardNth[i_,i_] -> StandardCenteredDifferenceOperator[2,fdOrder/2,i], +mathematica code PDstandardNth[i_,j_] -> StandardCenteredDifferenceOperator[1,fdOrder/2,i] * +mathematica code StandardCenteredDifferenceOperator[1,fdOrder/2,j], +mathematica code PDdissipationNth[i_] -> +mathematica code (-1)^(fdOrder/2) * +mathematica code spacing[i]^(fdOrder+1) / 2^(fdOrder+2) * +mathematica code StandardCenteredDifferenceOperator[fdOrder+2,fdOrder/2+1,i], +mathematica blank +mathematica comment (* PD: These come from my mathematica notebook +mathematica comment "Upwind-Kranc-Convert.nb" that converts upwinding finite +mathematica comment differencing operators generated by +mathematica comment StandardUpwindDifferenceOperator into this form *) +mathematica blank +mathematica code Sequence@@Flatten[Table[ +mathematica code {PDupwindNth[i] -> Switch[fdOrder, +mathematica code 2, (dir[i]*(-3 + 4*shift[i]^dir[i] - shift[i]^(2*dir[i])))/(2*spacing[i]), +mathematica code 4, (dir[i]*(-10 - 3/shift[i]^dir[i] + 18*shift[i]^dir[i] - +mathematica code 6*shift[i]^(2*dir[i]) + shift[i]^(3*dir[i])))/(12*spacing[i]), +mathematica code 6, (dir[i]*(-35 + 2/shift[i]^(2*dir[i]) - 24/shift[i]^dir[i] + 80*shift[i]^dir[i] - +mathematica code 30*shift[i]^(2*dir[i]) + 8*shift[i]^(3*dir[i]) - shift[i]^(4*dir[i])))/(60*spacing[i]), +mathematica code 8, (dir[i]*(-378 - 5/shift[i]^(3*dir[i]) + 60/shift[i]^(2*dir[i]) - 420/shift[i]^dir[i] + +mathematica code 1050*shift[i]^dir[i] - 420*shift[i]^(2*dir[i]) + 140*shift[i]^(3*dir[i]) - 30*shift[i]^(4*dir[i]) + +mathematica code 3*shift[i]^(5*dir[i])))/(840*spacing[i])], +mathematica blank +mathematica code PDupwindNthAnti[i] -> Switch[fdOrder, +mathematica code 2, (+1 shift[i]^(-2) -4 shift[i]^(-1) +0 shift[i]^( 0) +4 shift[i]^(+1) -1 shift[i]^(+2)) / (4 spacing[i]), +mathematica code 4, (-1 shift[i]^(-3) +6 shift[i]^(-2) -21 shift[i]^(-1 )+0 shift[i]^( 0) +21 shift[i]^(+1) +mathematica code -6 shift[i]^(+2) +1 shift[i]^(+3)) / (24 spacing[i]), +mathematica code 6, (+1 shift[i]^(-4) -8 shift[i]^(-3) +32 shift[i]^(-2) -104 shift[i]^(-1) +0 shift[i]^( 0) +mathematica code +104 shift[i]^(+1) -32 shift[i]^(+2) +8 shift[i]^(+3) -1 shift[i]^(+4)) / (120 spacing[i]), +mathematica code 8, (-3 shift[i]^(-5) +30 shift[i]^(-4) -145 shift[i]^(-3) +480 shift[i]^(-2) -1470 shift[i]^(-1) +mathematica code +0 shift[i]^( 0) +1470 shift[i]^(+1) -480 shift[i]^(+2) +145 shift[i]^(+3) -30 shift[i]^(+4) +mathematica code +3 shift[i]^(+5)) / (1680 spacing[i])], +mathematica blank +mathematica code PDupwindNthSymm[i] -> Switch[fdOrder, +mathematica code 2, (-1 shift[i]^(-2) +4 shift[i]^(-1) -6 shift[i]^( 0) +4 shift[i]^(+1) -1 shift[i]^(+2)) / (4 spacing[i]), +mathematica code 4, (+1 shift[i]^(-3) -6 shift[i]^(-2) +15 shift[i]^(-1) -20 shift[i]^( 0) +15 shift[i]^(+1) +mathematica code -6 shift[i]^(+2) +1 shift[i]^(+3)) / (24 spacing[i]), +mathematica code 6, (-1 shift[i]^(-4) +8 shift[i]^(-3) - 28 shift[i]^(-2)+56 shift[i]^(-1)-70 shift[i]^( 0) +mathematica code +56 shift[i]^(+1) -28 shift[i]^(+2) +8 shift[i]^(+3) -1 shift[i]^(+4)) / (120 spacing[i]), +mathematica code 8, (+3 shift[i]^(-5) -30 shift[i]^(-4) +135 shift[i]^(-3) -360 shift[i]^(-2) +630 shift[i]^(-1) +mathematica code -756 shift[i]^( 0) +630 shift[i]^(+1) -360 shift[i]^(+2) +135 shift[i]^(+3) -30 shift[i]^(+4) +mathematica code +3 shift[i]^(+5)) / (1680 spacing[i])], +mathematica blank +mathematica comment (* TODO: make these higher order stencils *) +mathematica code PDonesided[i] -> dir[i] (-1 + shift[i]^dir[i]) / spacing[i]} /. i->j, {j,1,3}],1] +mathematica code }; +mathematica blank +mathematica code PD = PDstandardNth; +mathematica code PDu = PDupwindNth; +mathematica code PDua = PDupwindNthAnti; +mathematica code PDus = PDupwindNthSymm; +mathematica comment (* PDo = PDonesided; *) +mathematica code PDdiss = PDdissipationNth; +mathematica blank +mathematica code If [splitUpwindDerivs, +mathematica code Upwind[dir_, var_, idx_] := dir PDua[var,idx] + Abs[dir] PDus[var,idx], +mathematica code Upwind[dir_, var_, idx_] := dir PDu[var,idx]]; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Tensors *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica comment (* Register the tensor quantities with the TensorTools package *) +mathematica code Map [DefineTensor, +mathematica code {normal, tangentA, tangentB, dir, +mathematica code nn, nu, nlen, nlen2, su, vg, +mathematica code xx, rr, th, ph, +mathematica code admg, admK, admalpha, admdtalpha, admbeta, admdtbeta, H, M, +mathematica code g, detg, gu, G, R, trR, Km, trK, cdphi, cdphi2, +mathematica code phi, gt, At, Xt, Xtn, Theta, Z, +mathematica code alpha, A, beta, B, Atm, Atu, trA, Ats, trAts, +mathematica code dottrK, dotXt, +mathematica code cXt, cS, cA, +mathematica code e4phi, em4phi, ddetg, detgt, gtu, ddetgt, dgtu, ddgtu, Gtl, Gtlu, Gt, +mathematica code Rt, Rphi, gK, +mathematica code T00, T0, T, rho, S, +mathematica code x, y, z, r, +mathematica code epsdiss}]; +mathematica blank +mathematica comment (* NOTE: It seems as if Lie[.,.] did not take these tensor weights +mathematica comment into account. Presumably, CD[.,.] and CDt[.,.] don't do this either. *) +mathematica code SetTensorAttribute[phi, TensorWeight, +1/6]; +mathematica code SetTensorAttribute[gt, TensorWeight, -2/3]; +mathematica code SetTensorAttribute[Xt, TensorWeight, +2/3]; +mathematica code SetTensorAttribute[At, TensorWeight, -2/3]; +mathematica code SetTensorAttribute[cXt, TensorWeight, +2/3]; +mathematica code SetTensorAttribute[cS, TensorWeight, +2 ]; +mathematica blank +mathematica code Map [AssertSymmetricIncreasing, +mathematica code {admg[la,lb], admK[la,lb], g[la,lb], K[la,lb], R[la,lb], cdphi2[la,lb], +mathematica code gt[la,lb], At[la,lb], Ats[la,lb], Rt[la,lb], Rphi[la,lb], T[la,lb]}]; +mathematica code AssertSymmetricIncreasing [G[ua,lb,lc], lb, lc]; +mathematica code AssertSymmetricIncreasing [Gtl[la,lb,lc], lb, lc]; +mathematica code AssertSymmetricIncreasing [Gt[ua,lb,lc], lb, lc]; +mathematica code AssertSymmetricIncreasing [gK[la,lb,lc], la, lb]; +mathematica code Map [AssertSymmetricIncreasing, +mathematica code {gu[ua,ub], gtu[ua,ub], Atu[ua,ub]}]; +mathematica code AssertSymmetricIncreasing [dgtu[ua,ub,lc], ua, ub]; +mathematica code AssertSymmetricIncreasing [ddgtu[ua,ub,lc,ld], ua, ub]; +mathematica code AssertSymmetricIncreasing [ddgtu[ua,ub,lc,ld], lc, ld]; +mathematica blank +mathematica code DefineConnection [CD, PD, G]; +mathematica code DefineConnection [CDt, PD, Gt]; +mathematica blank +mathematica comment (* Use the CartGrid3D variable names *) +mathematica code x1=x; x2=y; x3=z; +mathematica blank +mathematica comment (* Use the ADMBase variable names *) +mathematica code admg11=gxx; admg12=gxy; admg22=gyy; admg13=gxz; admg23=gyz; admg33=gzz; +mathematica code admK11=kxx; admK12=kxy; admK22=kyy; admK13=kxz; admK23=kyz; admK33=kzz; +mathematica code admalpha=alp; +mathematica code admdtalpha=dtalp; +mathematica code admbeta1=betax; admbeta2=betay; admbeta3=betaz; +mathematica code admdtbeta1=dtbetax; admdtbeta2=dtbetay; admdtbeta3=dtbetaz; +mathematica blank +mathematica comment (* Use the TmunuBase variable names *) +mathematica code T00=eTtt; +mathematica code T01=eTtx; T02=eTty; T03=eTtz; +mathematica code T11=eTxx; T12=eTxy; T22=eTyy; T13=eTxz; T23=eTyz; T33=eTzz; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Expressions *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica comment (* enum constants for conformalMethod; these must be consistent +mathematica comment with the definition of the Cactus parameter conformalMethod *) +mathematica code CMphi = 0; +mathematica code CMW = 1; +mathematica blank +mathematica code detgExpr = Det [MatrixOfComponents [g [la,lb]]]; +mathematica code ddetgExpr[la_] = +mathematica code Sum [D[Det[MatrixOfComponents[g[la, lb]]], X] PD[X, la], +mathematica code {X, Union[Flatten[MatrixOfComponents[g[la, lb]]]]}]; +mathematica blank +mathematica code detgtExpr = Det [MatrixOfComponents [gt[la,lb]]]; +mathematica code ddetgtExpr[la_] = +mathematica code Sum [D[Det[MatrixOfComponents[gt[la, lb]]], X] PD[X, la], +mathematica code {X, Union[Flatten[MatrixOfComponents[gt[la, lb]]]]}]; +mathematica blank +mathematica code etaExpr = SpatialBetaDriverRadius / Max [r, SpatialBetaDriverRadius]; +mathematica code thetaExpr = Min [Exp [1 - r / SpatialShiftGammaCoeffRadius], 1]; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Groups *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code evolvedGroups = +mathematica code {SetGroupName [CreateGroupFromTensor [phi ], prefix <> "log_confac"], +mathematica code SetGroupName [CreateGroupFromTensor [gt[la,lb]], prefix <> "metric" ], +mathematica code SetGroupName [CreateGroupFromTensor [Xt[ua] ], prefix <> "Gamma" ], +mathematica code SetGroupName [CreateGroupFromTensor [trK ], prefix <> "trace_curv"], +mathematica code SetGroupName [CreateGroupFromTensor [At[la,lb]], prefix <> "curv" ], +mathematica code SetGroupName [CreateGroupFromTensor [alpha ], prefix <> "lapse" ], +mathematica code SetGroupName [CreateGroupFromTensor [A ], prefix <> "dtlapse" ], +mathematica code SetGroupName [CreateGroupFromTensor [beta[ua] ], prefix <> "shift" ], +mathematica code SetGroupName [CreateGroupFromTensor [B[ua] ], prefix <> "dtshift" ], +mathematica code IfCCZ4[SetGroupName[CreateGroupFromTensor[Theta], prefix <> "Theta"]]}; +mathematica code evaluatedGroups = +mathematica code {SetGroupName [CreateGroupFromTensor [H ], prefix <> "Ham"], +mathematica code SetGroupName [CreateGroupFromTensor [M[la] ], prefix <> "mom"], +mathematica code SetGroupName [CreateGroupFromTensor [cS ], prefix <> "cons_detg"], +mathematica code SetGroupName [CreateGroupFromTensor [cXt[ua]], prefix <> "cons_Gamma"], +mathematica code SetGroupName [CreateGroupFromTensor [cA ], prefix <> "cons_traceA"]}; +mathematica blank +mathematica code declaredGroups = Join [evolvedGroups, evaluatedGroups]; +mathematica code declaredGroupNames = Map [First, declaredGroups]; +mathematica blank +mathematica blank +mathematica blank +mathematica code extraGroups = +mathematica code {{"grid::coordinates", {x, y, z, r}}, +mathematica code {"ADMBase::metric", {gxx, gxy, gxz, gyy, gyz, gzz}}, +mathematica code {"ADMBase::curv", {kxx, kxy, kxz, kyy, kyz, kzz}}, +mathematica code {"ADMBase::lapse", {alp}}, +mathematica code {"ADMBase::dtlapse", {dtalp}}, +mathematica code {"ADMBase::shift", {betax, betay, betaz}}, +mathematica code {"ADMBase::dtshift", {dtbetax, dtbetay, dtbetaz}}, +mathematica code {"TmunuBase::stress_energy_scalar", {eTtt}}, +mathematica code {"TmunuBase::stress_energy_vector", {eTtx, eTty, eTtz}}, +mathematica code {"TmunuBase::stress_energy_tensor", {eTxx, eTxy, eTxz, eTyy, eTyz, eTzz}} +mathematica code }; +mathematica blank +mathematica code groups = Join [declaredGroups, extraGroups]; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Initial data *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code initialCalc = +mathematica code { +mathematica code Name -> thorn <> "_Minkowski", +mathematica code Schedule -> {"IN ADMBase_InitialData"}, +mathematica code ConditionalOnKeyword -> {"my_initial_data", "Minkowski"}, +mathematica code Equations -> +mathematica code { +mathematica code phi -> IfThen[conformalMethod==CMW, 1, 0], +mathematica code gt[la,lb] -> KD[la,lb], +mathematica code trK -> 0, +mathematica code At[la,lb] -> 0, +mathematica code Xt[ua] -> 0, +mathematica code alpha -> 1, +mathematica code A -> 0, +mathematica code beta[ua] -> 0, +mathematica code B[ua] -> 0, +mathematica code IfCCZ4[Theta -> 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Split a calculation *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code PartialCalculation[calc_, suffix_, updates_, evolVars_] := +mathematica code Module[ +mathematica code {name, calc1, replaces, calc2, vars, patterns, eqs, calc3}, +mathematica comment (* Add suffix to name *) +mathematica code name = lookup[calc, Name] <> suffix; +mathematica code calc1 = mapReplace[calc, Name, name]; +mathematica comment (* Replace some entries in the calculation *) +mathematica comment (* replaces = Map[Function[rule, mapReplace[#, rule[[1]], rule[[2]]]&], updates]; *) +mathematica code replaces = updates //. (lhs_ -> rhs_) -> (mapReplace[#, lhs, rhs]&); +mathematica code calc2 = Apply[Composition, replaces][calc1]; +mathematica comment (* Remove unnecessary equations *) +mathematica code vars = Join[evolVars, lookup[calc2, Shorthands]]; +mathematica code patterns = Replace[vars, { Tensor[n_,__] -> Tensor[n,__] , +mathematica code dot[Tensor[n_,__]] -> dot[Tensor[n,__]]}, 1]; +mathematica code eqs = FilterRules[lookup[calc, Equations], patterns]; +mathematica code calc3 = mapReplace[calc2, Equations, eqs]; +mathematica code calc3 +mathematica code ]; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Convert from ADMBase *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code convertFromADMBaseCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertFromADMBase", +mathematica code Schedule -> {"AT initial AFTER ADMBase_PostInitial"}, +mathematica code ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, +mathematica code Shorthands -> {g[la,lb], detg, gu[ua,ub], em4phi}, +mathematica code Equations -> +mathematica code { +mathematica code g[la,lb] -> admg[la,lb], +mathematica code detg -> detgExpr, +mathematica code gu[ua,ub] -> 1/detg detgExpr MatrixInverse [g[ua,ub]], +mathematica blank +mathematica code phi -> IfThen[conformalMethod==CMW, detg^(-1/6), Log[detg]/12], +mathematica code em4phi -> IfThen[conformalMethod==CMW, phi^2, Exp[-4 phi]], +mathematica code gt[la,lb] -> em4phi g[la,lb], +mathematica blank +mathematica code trK -> gu[ua,ub] admK[la,lb], +mathematica code At[la,lb] -> em4phi (admK[la,lb] - (1/3) g[la,lb] trK), +mathematica blank +mathematica code alpha -> admalpha, +mathematica blank +mathematica code beta[ua] -> admbeta[ua], +mathematica blank +mathematica code IfCCZ4[Theta -> 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica code convertFromADMBaseGammaCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertFromADMBaseGamma", +mathematica code Schedule -> {"AT initial AFTER " <> thorn <> "_convertFromADMBase"}, +mathematica code ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, +mathematica comment (* +mathematica comment Where -> InteriorNoSync, +mathematica comment *) +mathematica comment (* Do not synchronise right after this routine; instead, synchronise +mathematica comment after extrapolating *) +mathematica code Where -> Interior, +mathematica comment (* Synchronise after this routine, so that the refinement boundaries +mathematica comment are set correctly before extrapolating. (We will need to +mathematica comment synchronise again after extrapolating because extrapolation does +mathematica comment not fill ghost zones, but this is irrelevant here.) *) +mathematica code Shorthands -> {dir[ua], +mathematica code detgt, gtu[ua,ub], Gt[ua,lb,lc], theta}, +mathematica code Equations -> +mathematica code { +mathematica code dir[ua] -> Sign[beta[ua]], +mathematica blank +mathematica code detgt -> 1 (* detgtExpr *), +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica code Gt[ua,lb,lc] -> 1/2 gtu[ua,ud] +mathematica code (PD[gt[lb,ld],lc] + PD[gt[lc,ld],lb] - PD[gt[lb,lc],ld]), +mathematica code Xt[ua] -> gtu[ub,uc] Gt[ua,lb,lc], +mathematica blank +mathematica comment (* +mathematica comment A -> - admdtalpha / (harmonicF alpha^harmonicN) (LapseAdvectionCoeff - 1), +mathematica comment *) +mathematica comment (* If LapseACoeff=0, then A is not evolved, in the sense that it +mathematica comment does not influence the time evolution of other variables. *) +mathematica code A -> IfThen [LapseACoeff != 0, +mathematica code 1 / (- harmonicF alpha^harmonicN) +mathematica code (+ admdtalpha +mathematica code - LapseAdvectionCoeff Upwind[beta[ua], alpha, la]), +mathematica code 0], +mathematica blank +mathematica code theta -> thetaExpr, +mathematica blank +mathematica comment (* If ShiftBCoeff=0 or theta ShiftGammaCoeff=0, then B^i is not +mathematica comment evolved, in the sense that it does not influence the time +mathematica comment evolution of other variables. *) +mathematica code B[ua] -> IfThen [ShiftGammaCoeff ShiftBCoeff != 0, +mathematica code 1 / (theta ShiftGammaCoeff) +mathematica code (+ admdtbeta[ua] +mathematica code - ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb]), +mathematica code 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (* Initialise the Gamma variables to 0. This is necessary with +mathematica comment multipatch because convertFromADMBaseGamma does not perform the +mathematica comment conversion in the boundary points, and the order in which symmetry +mathematica comment (interpatch) and outer boundary conditions is applied means that +mathematica comment points which are both interpatch and symmetry points are never +mathematica comment initialised. *) +mathematica code initGammaCalc = +mathematica code { +mathematica code Name -> thorn <> "_InitGamma", +mathematica code Schedule -> {"AT initial BEFORE " <> thorn <> "_convertFromADMBaseGamma"}, +mathematica code ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, +mathematica code Where -> Everywhere, +mathematica code Equations -> +mathematica code { +mathematica code Xt[ua] -> 0, +mathematica code A -> 0, +mathematica code B[ua] -> 0 +mathematica code } +mathematica code }; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Convert to ADMBase *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code convertToADMBaseCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertToADMBase", +mathematica code Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, +mathematica code Where -> Everywhere, +mathematica code Shorthands -> {e4phi}, +mathematica code Equations -> +mathematica code { +mathematica code e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], +mathematica code admg[la,lb] -> e4phi gt[la,lb], +mathematica code admK[la,lb] -> e4phi At[la,lb] + (1/3) admg[la,lb] trK, +mathematica code admalpha -> alpha, +mathematica code admbeta[ua] -> beta[ua] +mathematica code } +mathematica code }; +mathematica blank +mathematica code convertToADMBaseDtLapseShiftCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertToADMBaseDtLapseShift", +mathematica code Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, +mathematica code ConditionalOnKeyword -> {"dt_lapse_shift_method", "correct"}, +mathematica code Where -> Interior, +mathematica code Shorthands -> {dir[ua], detgt, gtu[ua,ub], eta, theta}, +mathematica code Equations -> +mathematica code { +mathematica code dir[ua] -> Sign[beta[ua]], +mathematica blank +mathematica code detgt -> 1 (* detgtExpr *), +mathematica comment (* This leads to simpler code... *) +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica blank +mathematica code eta -> etaExpr, +mathematica code theta -> thetaExpr, +mathematica blank +mathematica comment (* see RHS *) +mathematica comment (* +mathematica comment admdtalpha -> - harmonicF alpha^harmonicN +mathematica comment ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK) +mathematica comment + LapseAdvectionCoeff beta[ua] PDu[alpha,la], +mathematica comment *) +mathematica code admdtalpha -> - harmonicF alpha^harmonicN +mathematica code (+ LapseACoeff A +mathematica code + ((1 - LapseACoeff) +mathematica code (trK - IfCCZ4[2 Theta, 0]))) +mathematica code + LapseAdvectionCoeff Upwind[beta[ua], alpha, la], +mathematica code admdtbeta[ua] -> IfThen[harmonicShift, +mathematica code - 1/2 gtu[ua,uj] phi alpha +mathematica code (- 2 alpha PD[phi,lj] +mathematica code + 2 phi PD[alpha,lj] +mathematica code + gtu[uk,ul] phi alpha +mathematica code (PD[gt[lk,ll],lj] - 2 PD[gt[lj,lk],ll])), +mathematica comment (* else *) +mathematica code + theta ShiftGammaCoeff +mathematica code (+ ShiftBCoeff B[ua] +mathematica code + (1 - ShiftBCoeff) +mathematica code (Xt[ua] - eta BetaDriver beta[ua]))] +mathematica code + ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb] +mathematica code } +mathematica code }; +mathematica blank +mathematica code convertToADMBaseDtLapseShiftBoundaryCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertToADMBaseDtLapseShiftBoundary", +mathematica code Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, +mathematica code ConditionalOnKeyword -> {"dt_lapse_shift_method", "correct"}, +mathematica code Where -> BoundaryWithGhosts, +mathematica code Shorthands -> {detgt, gtu[ua,ub], eta, theta}, +mathematica code Equations -> +mathematica code { +mathematica code detgt -> 1 (* detgtExpr *), +mathematica comment (* This leads to simpler code... *) +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica blank +mathematica code eta -> etaExpr, +mathematica code theta -> thetaExpr, +mathematica blank +mathematica comment (* see RHS, but omit derivatives near the boundary *) +mathematica comment (* +mathematica comment admdtalpha -> - harmonicF alpha^harmonicN +mathematica comment ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK), +mathematica comment *) +mathematica code admdtalpha -> - harmonicF alpha^harmonicN +mathematica code (+ LapseACoeff A +mathematica code + ((1 - LapseACoeff) +mathematica code (trK - IfCCZ4[2 Theta, 0]))), +mathematica code admdtbeta[ua] -> IfThen[harmonicShift, +mathematica code 0, +mathematica comment (* else *) +mathematica code + theta ShiftGammaCoeff +mathematica code (+ ShiftBCoeff B[ua] +mathematica code + (1 - ShiftBCoeff) +mathematica code (Xt[ua] - eta BetaDriver beta[ua]))] +mathematica code } +mathematica code }; +mathematica blank +mathematica code convertToADMBaseFakeDtLapseShiftCalc = +mathematica code { +mathematica code Name -> thorn <> "_convertToADMBaseFakeDtLapseShift", +mathematica code Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, +mathematica code ConditionalOnKeyword -> {"dt_lapse_shift_method", "noLapseShiftAdvection"}, +mathematica code Where -> Everywhere, +mathematica code Shorthands -> {detgt, gtu[ua,ub], eta, theta}, +mathematica code Equations -> +mathematica code { +mathematica code detgt -> 1 (* detgtExpr *), +mathematica comment (* This leads to simpler code... *) +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica blank +mathematica code eta -> etaExpr, +mathematica code theta -> thetaExpr, +mathematica blank +mathematica comment (* see RHS, but omit derivatives everywhere (which is wrong, but +mathematica comment faster, since it does not require synchronisation or boundary +mathematica comment conditions) *) +mathematica comment (* +mathematica comment admdtalpha -> - harmonicF alpha^harmonicN +mathematica comment ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK), +mathematica comment *) +mathematica code admdtalpha -> - harmonicF alpha^harmonicN +mathematica code (+ LapseACoeff A +mathematica code + ((1 - LapseACoeff) +mathematica code (trK - IfCCZ4[2 Theta, 0]))), +mathematica code admdtbeta[ua] -> IfThen[harmonicShift, +mathematica code 0, +mathematica comment (* else *) +mathematica code + theta ShiftGammaCoeff +mathematica code (+ ShiftBCoeff B[ua] +mathematica code + (1 - ShiftBCoeff) +mathematica code (Xt[ua] - eta BetaDriver beta[ua]))] +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Evolution equations *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code evolCalc = +mathematica code { +mathematica code Name -> thorn <> "_RHS", +mathematica code Schedule -> {"IN " <> thorn <> "_evolCalcGroup"}, +mathematica comment (* +mathematica comment Where -> Interior, +mathematica comment *) +mathematica comment (* Synchronise the RHS grid functions after this routine, so that +mathematica comment the refinement boundaries are set correctly before applying the +mathematica comment radiative boundary conditions. *) +mathematica code Where -> InteriorNoSync, +mathematica code ConditionalOnKeyword -> {"RHS_split", "combined"}, +mathematica code Shorthands -> {dir[ua], +mathematica code detgt, gtu[ua,ub], +mathematica code Gt[ua,lb,lc], Gtl[la,lb,lc], Gtlu[la,lb,uc], Xtn[ua], +mathematica code Rt[la,lb], Rphi[la,lb], R[la,lb], +mathematica code Atm[ua,lb], Atu[ua,ub], +mathematica code e4phi, em4phi, cdphi[la], cdphi2[la,lb], g[la,lb], detg, +mathematica code gu[ua,ub], Ats[la,lb], trAts, eta, theta, +mathematica code rho, S[la], trS, fac1, fac2, dottrK, dotXt[ua], +mathematica code epsdiss[ua], IfCCZ4[Z[ua]], IfCCZ4[dotTheta]}, +mathematica code Equations -> +mathematica code { +mathematica code dir[ua] -> Sign[beta[ua]], +mathematica blank +mathematica code detgt -> 1 (* detgtExpr *), +mathematica blank +mathematica comment (* This leads to simpler code... *) +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica code Gtl[la,lb,lc] -> 1/2 +mathematica code (PD[gt[lb,la],lc] + PD[gt[lc,la],lb] - PD[gt[lb,lc],la]), +mathematica code Gtlu[la,lb,uc] -> gtu[uc,ud] Gtl[la,lb,ld], +mathematica code Gt[ua,lb,lc] -> gtu[ua,ud] Gtl[ld,lb,lc], +mathematica blank +mathematica comment (* The conformal connection functions calculated from the conformal metric, +mathematica comment used instead of Xt where no derivatives of Xt are taken *) +mathematica code Xtn[ui] -> gtu[uj,uk] Gt[ui,lj,lk], +mathematica blank +mathematica code e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], +mathematica code em4phi -> 1 / e4phi, +mathematica code g[la,lb] -> e4phi gt[la,lb], +mathematica code detg -> detgExpr, +mathematica code gu[ua,ub] -> em4phi gtu[ua,ub], +mathematica blank +mathematica comment (* The Z quantities *) +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (23) *) +mathematica code IfCCZ4[ +mathematica code Z[ud] -> (1/2) gu[ua,ud] (- PD[gt[la,lb],lc] gtu[ub,uc] + gt[la,lc] Xt[uc]) +mathematica code ], +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (18) *) +mathematica comment (* Adding Z term by changing Xtn to Xt *) +mathematica code Rt[li,lj] -> - (1/2) gtu[ul,um] PD[gt[li,lj],ll,lm] +mathematica code + (1/2) gt[lk,li] PD[Xt[uk],lj] +mathematica code + (1/2) gt[lk,lj] PD[Xt[uk],li] +mathematica code + (1/2) Xtn[uk] Gtl[li,lj,lk] +mathematica code + (1/2) Xtn[uk] Gtl[lj,li,lk] +mathematica code + (+ Gt[uk,li,ll] Gtlu[lj,lk,ul] +mathematica code + Gt[uk,lj,ll] Gtlu[li,lk,ul] +mathematica code + Gt[uk,li,ll] Gtlu[lk,lj,ul]), +mathematica blank +mathematica code fac1 -> IfThen[conformalMethod==CMW, -1/(2 phi), 1], +mathematica code cdphi[la] -> fac1 CDt[phi,la], +mathematica code fac2 -> IfThen[conformalMethod==CMW, 1/(2 phi^2), 0], +mathematica code cdphi2[la,lb] -> fac1 CDt[phi,la,lb] + fac2 CDt[phi,la] CDt[phi,lb], +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (15) *) +mathematica code Rphi[li,lj] -> - 2 cdphi2[lj,li] +mathematica code - 2 gt[li,lj] gtu[ul,un] cdphi2[ll,ln] +mathematica code + 4 cdphi[li] cdphi[lj] +mathematica code - 4 gt[li,lj] gtu[ul,un] cdphi[ln] cdphi[ll], +mathematica blank +mathematica code Atm[ua,lb] -> gtu[ua,uc] At[lc,lb], +mathematica code Atu[ua,ub] -> Atm[ua,lc] gtu[ub,uc], +mathematica blank +mathematica code R[la,lb] -> Rt[la,lb] + Rphi[la,lb], +mathematica code IfCCZ4[ +mathematica code R[la,lb] -> R[la,lb] + (2/phi) (+ g[la,lc] Z[uc] PD[phi,lb] +mathematica code + g[lb,lc] Z[uc] PD[phi,la] - g[la,lb] Z[uc] PD[phi,lc]) +mathematica code + e4phi Z[uc] PD[gt[la,lb],lc] +mathematica code ], +mathematica blank +mathematica comment (* Matter terms *) +mathematica blank +mathematica comment (* rho = n^a n^b T_ab *) +mathematica code rho -> addMatter +mathematica code (1/alpha^2 (T00 - 2 beta[ui] T0[li] + beta[ui] beta[uj] T[li,lj])), +mathematica blank +mathematica comment (* S_i = -p^a_i n^b T_ab, where p^a_i = delta^a_i + n^a n_i *) +mathematica code S[li] -> addMatter (-1/alpha (T0[li] - beta[uj] T[li,lj])), +mathematica blank +mathematica comment (* trS = gamma^ij T_ij *) +mathematica code trS -> addMatter (em4phi gtu[ui,uj] T[li,lj]), +mathematica blank +mathematica comment (* RHS terms *) +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (10) *) +mathematica comment (* PRD 67 084023 (2003), eqn. (16) and (23) *) +mathematica code dot[phi] -> IfThen[conformalMethod==CMW, 1/3 phi, -1/6] +mathematica code (alpha trK - PD[beta[ua],la]), +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (9) *) +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (14) *) +mathematica comment (* removing trA from Aij ensures that detg = 1 *) +mathematica code dot[gt[la,lb]] -> - 2 alpha (At[la,lb] - IfCCZ4[(1/3) At[lc,ld] gtu[uc,ud] gt[la,lb], 0]) +mathematica code + gt[la,lc] PD[beta[uc],lb] + gt[lb,lc] PD[beta[uc],la] +mathematica code - (2/3) gt[la,lb] PD[beta[uc],lc], +mathematica comment (* PRD 62, 044034 (2000), eqn. (20) *) +mathematica comment (* PRD 67 084023 (2003), eqn (26) *) +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (19) *) +mathematica comment (* Adding Z terms by changing Xtn to Xt, +mathematica comment also adding extra Z and Theta terms *) +mathematica code dotXt[ui] -> - 2 Atu[ui,uj] PD[alpha,lj] +mathematica code + 2 alpha (+ Gt[ui,lj,lk] Atu[uk,uj] +mathematica code - (2/3) gtu[ui,uj] PD[trK,lj] +mathematica code + 6 Atu[ui,uj] cdphi[lj]) +mathematica code + gtu[uj,ul] PD[beta[ui],lj,ll] +mathematica code + (1/3) gtu[ui,uj] PD[beta[ul],lj,ll] +mathematica code - Xtn[uj] PD[beta[ui],lj] +mathematica code + (2/3) Xtn[ui] PD[beta[uj],lj] +mathematica code + IfCCZ4[ +mathematica code + GammaShift 2 e4phi (- Z[uj] PD[beta[ui],lj] +mathematica code + (2/3) Z[ui] PD[beta[uj],lj]) +mathematica code - (4/3) alpha e4phi Z[ui] trK +mathematica code + 2 gtu[ui,uj] (+ alpha PD[Theta,lj] +mathematica code - Theta PD[alpha,lj]) +mathematica code - 2 alpha e4phi dampk1 Z[ui], +mathematica code 0] +mathematica comment (* Equation (4.28) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) +mathematica code + addMatter (- 16 Pi alpha gtu[ui,uj] S[lj]), +mathematica code dot[Xt[ui]] -> dotXt[ui], +mathematica blank +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (18) *) +mathematica code IfCCZ4[ +mathematica code dotTheta -> +mathematica code - PD[alpha,la] Z[ua] - dampk1 (2 + dampk2) alpha Theta +mathematica code + (1/2) alpha (gu[ua,ub] R[la,lb] - Atm[ua,lb] Atm[ub,la] + (2/3) trK^2 - 2 trK Theta) +mathematica code + addMatter (- 8 Pi alpha rho) +mathematica code ], +mathematica blank +mathematica code IfCCZ4[ +mathematica code dot[Theta] -> dotTheta +mathematica code ], +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (11) *) +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (17) *) +mathematica comment (* Adding the RHS of Theta to K, because K_Z4 = K_BSSN + 2 Theta *) +mathematica comment (* Also adding the Z term, as it has to cancel with the one in Theta *) +mathematica code dottrK -> - em4phi ( gtu[ua,ub] ( PD[alpha,la,lb] +mathematica code + 2 cdphi[la] PD[alpha,lb] ) +mathematica code - Xtn[ua] PD[alpha,la] ) +mathematica code + alpha (Atm[ua,lb] Atm[ub,la] + (1/3) trK^2) +mathematica code + IfCCZ4[ +mathematica code + 2 dotTheta + 2 PD[alpha,la] Z[ua] +mathematica code + dampk1 (1 - dampk2) alpha Theta, +mathematica code 0] +mathematica comment (* Equation (4.21) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) +mathematica code + addMatter (4 Pi alpha (rho + trS)), +mathematica code dot[trK] -> dottrK, +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (12) *) +mathematica comment (* TODO: Should we use the Hamiltonian constraint to make Rij tracefree? *) +mathematica comment (* gr-qc:1106.2254 (2011), eqn. (15) *) +mathematica comment (* Adding Z terms in the Ricci and Theta terms *) +mathematica code Ats[la,lb] -> - CDt[alpha,la,lb] + +mathematica code + 2 (PD[alpha,la] cdphi[lb] + PD[alpha,lb] cdphi[la] ) +mathematica code + alpha R[la,lb], +mathematica code trAts -> gu[ua,ub] Ats[la,lb], +mathematica code dot[At[la,lb]] -> + em4phi (+ Ats[la,lb] - (1/3) g[la,lb] trAts ) +mathematica code + alpha (+ ((trK - IfCCZ4[2 Theta, 0]) +mathematica code At[la,lb]) +mathematica code - 2 At[la,lc] Atm[uc,lb]) +mathematica code + At[la,lc] PD[beta[uc],lb] + At[lb,lc] PD[beta[uc],la] +mathematica code - (2/3) At[la,lb] PD[beta[uc],lc] +mathematica comment (* Equation (4.23) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) +mathematica code + addMatter (- em4phi alpha 8 Pi +mathematica code (T[la,lb] - (1/3) g[la,lb] trS)), +mathematica blank +mathematica comment (* dot[alpha] -> - harmonicF alpha^harmonicN trK, *) +mathematica comment (* dot[alpha] -> - harmonicF alpha^harmonicN A + Lie[alpha, beta], *) +mathematica comment (* +mathematica comment dot[alpha] -> - harmonicF alpha^harmonicN ( +mathematica comment (1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK) +mathematica comment + LapseAdvectionCoeff beta[ua] PDu[alpha,la], +mathematica comment dot[A] -> (1 - LapseAdvectionCoeff) (dottrK - AlphaDriver A), +mathematica comment *) +mathematica code dot[alpha] -> - harmonicF alpha^harmonicN +mathematica code (+ LapseACoeff A +mathematica code + ((1 - LapseACoeff) +mathematica code (+ trK - IfCCZ4[2 Theta, 0] +mathematica code + AlphaDriver (alpha - 1)))), +mathematica blank +mathematica code dot[A] -> + (LapseACoeff +mathematica code (+ dottrK - IfCCZ4[2 dotTheta, 0] +mathematica code - AlphaDriver A)), +mathematica blank +mathematica code eta -> etaExpr, +mathematica code theta -> thetaExpr, +mathematica blank +mathematica comment (* dot[beta[ua]] -> eta Xt[ua], *) +mathematica comment (* dot[beta[ua]] -> ShiftGammaCoeff alpha^ShiftAlphaPower B[ua], *) +mathematica code dot[beta[ua]] -> IfThen[harmonicShift, +mathematica code - 1/2 gtu[ua,uj] phi alpha +mathematica code (- 2 alpha PD[phi,lj] +mathematica code + 2 phi PD[alpha,lj] +mathematica code + gtu[uk,ul] phi alpha +mathematica code (PD[gt[lk,ll],lj] - 2 PD[gt[lj,lk],ll])), +mathematica comment (* else *) +mathematica code + theta ShiftGammaCoeff +mathematica code (+ ShiftBCoeff B[ua] +mathematica code + (1 - ShiftBCoeff) +mathematica code (Xt[ua] - eta BetaDriver beta[ua]))], +mathematica blank +mathematica code dot[B[ua]] -> + ShiftBCoeff (dotXt[ua] - eta BetaDriver B[ua]) +mathematica comment (* Note that this dotXt[ua] is not yet \partial_t \tilde \Gamma^i, because the +mathematica comment advection term has not yet been added. It is actually +mathematica comment \partial_t \tilde \Gamma^i - \beta^j \partial_j \tilde \Gamma^i *) +mathematica code } +mathematica code }; +mathematica blank +mathematica code advectCalc = +mathematica code { +mathematica code Name -> thorn <> "_Advect", +mathematica code Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> +mathematica code "AFTER (" <> thorn <> "_RHS " <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, +mathematica comment (* +mathematica comment Where -> Interior, +mathematica comment *) +mathematica comment (* Synchronise the RHS grid functions after this routine, so that +mathematica comment the refinement boundaries are set correctly before applying the +mathematica comment radiative boundary conditions. *) +mathematica code Where -> InteriorNoSync, +mathematica code ConditionalOnKeyword -> {"advection_split", "combined"}, +mathematica code Shorthands -> {dir[ua]}, +mathematica code Equations -> +mathematica code { +mathematica code dir[ua] -> Sign[beta[ua]], +mathematica blank +mathematica code dot[phi] -> dot[phi] + Upwind[beta[ua], phi, la], +mathematica blank +mathematica code dot[gt[la,lb]] -> dot[gt[la,lb]] + Upwind[beta[uc], gt[la,lb], lc], +mathematica blank +mathematica code dot[Xt[ui]] -> dot[Xt[ui]] + Upwind[beta[uj], Xt[ui], lj], +mathematica blank +mathematica code IfCCZ4[ +mathematica code dot[Theta] -> dot[Theta] + Upwind[beta[ua], Theta, la] +mathematica code ], +mathematica blank +mathematica code dot[trK] -> dot[trK] + Upwind[beta[ua], trK, la], +mathematica blank +mathematica code dot[At[la,lb]] -> dot[At[la,lb]] + Upwind[beta[uc], At[la,lb], lc], +mathematica blank +mathematica code dot[alpha] -> dot[alpha] +mathematica code + LapseAdvectionCoeff Upwind[beta[ua], alpha, la], +mathematica blank +mathematica code dot[A] -> dot[A] +mathematica code + LapseACoeff ( +mathematica code + LapseAdvectionCoeff Upwind[beta[ua], A, la] +mathematica code + (1 - LapseAdvectionCoeff) Upwind[beta[ua], trK, la]), +mathematica blank +mathematica code dot[beta[ua]] -> dot[beta[ua]] +mathematica code + ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb], +mathematica blank +mathematica code dot[B[ua]] -> dot[B[ua]] +mathematica code + ShiftBCoeff ( +mathematica code + ShiftAdvectionCoeff Upwind[beta[ub], B[ua], lb] +mathematica code + ((1 - ShiftAdvectionCoeff) +mathematica code Upwind[beta[ub], Xt[ua], lb])) +mathematica comment (* Note that the advection term \beta^j \partial_j \tilde \Gamma^i is not +mathematica comment subtracted here when ShiftAdvectionCoefficient == 1 because it was +mathematica comment implicitly subtracted before (see comment in previous calculation of +mathematica comment dot[B[ua]]. *) +mathematica code } +mathematica code }; +mathematica blank +mathematica code varsNames = { +mathematica code {"phi", dot[phi]}, +mathematica code {"gt", dot[gt[la,lb]]}, +mathematica code {"Xt", dot[Xt[ui]]}, +mathematica code {"trK", dot[trK]}, +mathematica code {"At", dot[At[la,lb]]}, +mathematica code {"alpha", dot[alpha]}, +mathematica code {"A", dot[A]}, +mathematica code {"beta", dot[beta[ua]]}, +mathematica code {"B", dot[B[ua]]}, +mathematica code IfCCZ4[{"Theta", dot[Theta]}] +mathematica code }; +mathematica blank +mathematica code advectCalcs = Map[ +mathematica code PartialCalculation[advectCalc, "_"<>ToString[First[#]], +mathematica code {ConditionalOnKeyword -> {"advection_split", +mathematica code "per variable"}}, +mathematica code {Last[#]}]&, +mathematica code varsNames]; +mathematica blank +mathematica code evolCalc1 = PartialCalculation[evolCalc, "1", +mathematica code { +mathematica code ConditionalOnKeyword -> {"RHS_split", "split At"} +mathematica code }, +mathematica code { +mathematica code dot[phi], +mathematica code dot[gt[la,lb]], +mathematica code dot[Xt[ui]], +mathematica code dot[trK], +mathematica code dot[alpha], +mathematica code dot[A], +mathematica code dot[beta[ua]], +mathematica code dot[B[ua]], +mathematica code IfCCZ4[dot[Theta]] +mathematica code }]; +mathematica blank +mathematica code evolCalc2 = PartialCalculation[evolCalc, "2", +mathematica code { +mathematica code ConditionalOnKeyword -> {"RHS_split", "split At"} +mathematica code }, +mathematica code { +mathematica code dot[At[la,lb]] +mathematica code }]; +mathematica blank +mathematica code dissCalc = +mathematica code { +mathematica code Name -> thorn <> "_Dissipation", +mathematica code Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> +mathematica code "AFTER (" <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, +mathematica code ConditionalOnKeyword -> {"apply_dissipation", "always"}, +mathematica code Where -> InteriorNoSync, +mathematica code Shorthands -> {epsdiss[ua]}, +mathematica code Equations -> +mathematica code { +mathematica code epsdiss[ua] -> EpsDiss, +mathematica code Sequence@@Table[ +mathematica code dot[var] -> dot[var] + epsdiss[ux] PDdiss[var,lx], +mathematica code {var, {phi, gt[la,lb], Xt[ui], IfCCZ4[Theta], trK, At[la,lb], +mathematica code alpha, A, beta[ua], B[ua]}}] +mathematica code } +mathematica code }; +mathematica blank +mathematica code dissCalcs = +mathematica code Table[ +mathematica code { +mathematica code Name -> thorn <> "_Dissipation_" <> ToString[var /. {Tensor[n_,__] -> n}], +mathematica code Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> +mathematica code "AFTER (" <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, +mathematica code ConditionalOnKeyword -> {"apply_dissipation", "always"}, +mathematica code Where -> InteriorNoSync, +mathematica code Shorthands -> {epsdiss[ua]}, +mathematica code Equations -> +mathematica code { +mathematica code epsdiss[ua] -> EpsDiss, +mathematica code dot[var] -> dot[var] + epsdiss[ux] PDdiss[var,lx] +mathematica code } +mathematica code }, +mathematica code {var, {phi, gt[la,lb], Xt[ui], IfCCZ4[Theta], trK, At[la,lb], +mathematica code alpha, A, beta[ua], B[ua]}} +mathematica code ]; +mathematica blank +mathematica code RHSStaticBoundaryCalc = +mathematica code { +mathematica code Name -> thorn <> "_RHSStaticBoundary", +mathematica code Schedule -> {"IN MoL_CalcRHS"}, +mathematica code ConditionalOnKeyword -> {"my_rhs_boundary_condition", "static"}, +mathematica code Where -> Boundary, +mathematica code Equations -> +mathematica code { +mathematica code dot[phi] -> 0, +mathematica code dot[gt[la,lb]] -> 0, +mathematica code dot[trK] -> 0, +mathematica code dot[At[la,lb]] -> 0, +mathematica code dot[Xt[ua]] -> 0, +mathematica code dot[alpha] -> 0, +mathematica code dot[A] -> 0, +mathematica code dot[beta[ua]] -> 0, +mathematica code dot[B[ua]] -> 0, +mathematica code IfCCZ4[dot[Theta] -> 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (* Initialise the RHS variables in analysis in case they are going to +mathematica comment be output - the noninterior points cannot be filled, so we define +mathematica comment them to be zero *) +mathematica code initRHSCalc = +mathematica code { +mathematica code Name -> thorn <> "_InitRHS", +mathematica code Schedule -> {"AT analysis BEFORE " <> thorn <> "_evolCalcGroup"}, +mathematica code Where -> Everywhere, +mathematica code Equations -> +mathematica code { +mathematica code dot[phi] -> 0, +mathematica code dot[gt[la,lb]] -> 0, +mathematica code dot[trK] -> 0, +mathematica code dot[At[la,lb]] -> 0, +mathematica code dot[Xt[ua]] -> 0, +mathematica code dot[alpha] -> 0, +mathematica code dot[A] -> 0, +mathematica code dot[beta[ua]] -> 0, +mathematica code dot[B[ua]] -> 0, +mathematica code IfCCZ4[dot[Theta] -> 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica code RHSRadiativeBoundaryCalc = +mathematica code { +mathematica code Name -> thorn <> "_RHSRadiativeBoundary", +mathematica code Schedule -> {"IN MoL_CalcRHS"}, +mathematica code ConditionalOnKeyword -> {"my_rhs_boundary_condition", "radiative"}, +mathematica code Where -> Boundary, +mathematica code Shorthands -> {dir[ua], +mathematica code detgt, gtu[ua,ub], em4phi, gu[ua,ub], +mathematica code nn[la], nu[ua], nlen, nlen2, su[ua], +mathematica code vg}, +mathematica code Equations -> +mathematica code { +mathematica code dir[ua] -> Sign[normal[ua]], +mathematica blank +mathematica code detgt -> 1 (* detgtExpr *), +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica code em4phi -> IfThen[conformalMethod==CMW, phi^2, Exp[-4 phi]], +mathematica code gu[ua,ub] -> em4phi gtu[ua,ub], +mathematica blank +mathematica code nn[la] -> Euc[la,lb] normal[ub], +mathematica code nu[ua] -> gu[ua,ub] nn[lb], +mathematica code nlen2 -> nu[ua] nn[la], +mathematica code nlen -> Sqrt[nlen2], +mathematica code su[ua] -> nu[ua] / nlen, +mathematica blank +mathematica code vg -> Sqrt[harmonicF], +mathematica blank +mathematica code dot[phi] -> - vg su[uc] PDo[phi ,lc], +mathematica code dot[gt[la,lb]] -> - su[uc] PDo[gt[la,lb],lc], +mathematica code dot[trK] -> - vg su[uc] PDo[trK ,lc], +mathematica code dot[At[la,lb]] -> - su[uc] PDo[At[la,lb],lc], +mathematica code dot[Xt[ua]] -> - su[uc] PDo[Xt[ua] ,lc], +mathematica code dot[alpha] -> - vg su[uc] PDo[alpha ,lc], +mathematica code dot[A] -> - vg su[uc] PDo[A ,lc], +mathematica code dot[beta[ua]] -> - su[uc] PDo[beta[ua] ,lc], +mathematica code dot[B[ua]] -> - su[uc] PDo[B[ua] ,lc], +mathematica code IfCCZ4[ +mathematica code dot[Theta] -> - vg su[uc] PDo[Theta ,lc] +mathematica code ] +mathematica code } +mathematica code }; +mathematica blank +mathematica code enforceCalc = +mathematica code { +mathematica code Name -> thorn <> "_enforce", +mathematica code Schedule -> {"IN MoL_PostStepModify"}, +mathematica code Shorthands -> {detgt, gtu[ua,ub], trAt}, +mathematica code Equations -> +mathematica code { +mathematica comment (* The following comment is still interesting, but is not correct +mathematica comment any more since it is now scheduled in MoL_PostStepModify instead: +mathematica blank +mathematica comment Enforcing the constraints needs to be a projection, because it +mathematica comment is applied in MoL_PostStep and may thus be applied multiple +mathematica comment times, not only during time evolution. Therefore detgt has to +mathematica comment be calculated correctly, without assuming that det gt_ij = 1, +mathematica comment which is not always the case (since we don't enforce it). On +mathematica comment the other hand, this may not be so important... *) +mathematica code detgt -> 1 (* detgtExpr *), +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica blank +mathematica code trAt -> gtu[ua,ub] At[la,lb], +mathematica blank +mathematica code At[la,lb] -> At[la,lb] - (1/3) gt[la,lb] trAt, +mathematica blank +mathematica code alpha -> Max[alpha, MinimumLapse] +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Boundary conditions *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code boundaryCalc = +mathematica code { +mathematica code Name -> thorn <> "_boundary", +mathematica code Schedule -> {"IN MoL_PostStep"}, +mathematica code ConditionalOnKeyword -> {"my_boundary_condition", "Minkowski"}, +mathematica code Where -> BoundaryWithGhosts, +mathematica code Equations -> +mathematica code { +mathematica code phi -> IfThen[conformalMethod==CMW, 1, 0], +mathematica code gt[la,lb] -> KD[la,lb], +mathematica code trK -> 0, +mathematica code At[la,lb] -> 0, +mathematica code Xt[ua] -> 0, +mathematica code alpha -> 1, +mathematica code A -> 0, +mathematica code beta[ua] -> 0, +mathematica code B[ua] -> 0, +mathematica code IfCCZ4[Theta -> 0] +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Constraint equations *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code constraintsCalc = +mathematica code { +mathematica code Name -> thorn <> "_constraints", +mathematica code Schedule -> Automatic, +mathematica code After -> "MoL_PostStep", +mathematica code Where -> Interior, +mathematica code Shorthands -> {detgt, ddetgt[la], gtu[ua,ub], Z[ua], +mathematica code Gt[ua,lb,lc], Gtl[la,lb,lc], Gtlu[la,lb,uc], Xtn[ua], +mathematica code e4phi, em4phi, +mathematica code g[la,lb], detg, gu[ua,ub], ddetg[la], G[ua,lb,lc], +mathematica code Rt[la,lb], Rphi[la,lb], R[la,lb], trR, Atm[ua,lb], +mathematica code gK[la,lb,lc], cdphi[la], cdphi2[la,lb], +mathematica code rho, S[la], fac1, fac2}, +mathematica code Equations -> +mathematica code { +mathematica code detgt -> 1 (* detgtExpr *), +mathematica code ddetgt[la] -> 0 (* ddetgtExpr[la] *), +mathematica blank +mathematica comment (* This leads to simpler code... *) +mathematica code gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], +mathematica code Gtl[la,lb,lc] -> 1/2 +mathematica code (PD[gt[lb,la],lc] + PD[gt[lc,la],lb] - PD[gt[lb,lc],la]), +mathematica code Gtlu[la,lb,uc] -> gtu[uc,ud] Gtl[la,lb,ld], +mathematica code Gt[ua,lb,lc] -> gtu[ua,ud] Gtl[ld,lb,lc], +mathematica blank +mathematica comment (* The conformal connection functions calculated from the conformal metric, +mathematica comment used instead of Xt where no derivatives of Xt are taken *) +mathematica code Xtn[ui] -> gtu[uj,uk] Gt[ui,lj,lk], +mathematica blank +mathematica code e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], +mathematica code em4phi -> 1 / e4phi, +mathematica code g[la,lb] -> e4phi gt[la,lb], +mathematica code detg -> e4phi^3, +mathematica code gu[ua,ub] -> em4phi gtu[ua,ub], +mathematica blank +mathematica comment (* The Z quantities *) +mathematica code IfCCZ4[ +mathematica code Z[ud] -> (1/2) gu[ua,ud] (- PD[gt[la,lb],lc] gtu[ub,uc] + gt[la,lc] Xt[uc]) +mathematica code ], +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (18) *) +mathematica code Rt[li,lj] -> - (1/2) gtu[ul,um] PD[gt[li,lj],ll,lm] +mathematica code + (1/2) gt[lk,li] PD[Xt[uk],lj] +mathematica code + (1/2) gt[lk,lj] PD[Xt[uk],li] +mathematica code + (1/2) Xtn[uk] Gtl[li,lj,lk] +mathematica code + (1/2) Xtn[uk] Gtl[lj,li,lk] +mathematica code + (+ Gt[uk,li,ll] Gtlu[lj,lk,ul] +mathematica code + Gt[uk,lj,ll] Gtlu[li,lk,ul] +mathematica code + Gt[uk,li,ll] Gtlu[lk,lj,ul]), +mathematica blank +mathematica comment (* From the long turducken paper. +mathematica comment This expression seems to give the same result as the one from 044034. *) +mathematica comment (* TODO: symmetrise correctly: (ij) = (1/2) [i+j] *) +mathematica comment (* +mathematica comment Rt[li,lj] -> - (1/2) gtu[uk,ul] PD[gt[li,lj],lk,ll] +mathematica comment + gt[lk,li] PD[Xt[uk],lj] + gt[lk,lj] PD[Xt[uk],li] +mathematica comment + gt[li,ln] Gt[un,lj,lk] gtu[um,ua] gtu[uk,ub] PD[gt[la,lb],lm] +mathematica comment + gt[lj,ln] Gt[un,li,lk] gtu[um,ua] gtu[uk,ub] PD[gt[la,lb],lm] +mathematica comment + gtu[ul,us] (+ 2 Gt[uk,ll,li] gt[lj,ln] Gt[un,lk,ls] +mathematica comment + 2 Gt[uk,ll,lj] gt[li,ln] Gt[un,lk,ls] +mathematica comment + Gt[uk,li,ls] gt[lk,ln] Gt[un,ll,lj]), +mathematica comment *) +mathematica blank +mathematica comment (* Below would be a straightforward calculation, +mathematica comment without taking any Gamma^i into account. +mathematica comment This expression gives a different answer! *) +mathematica comment (* +mathematica comment Rt[la,lb] -> + Gt[u1,l2,la] Gt[l1,lb,u2] - Gt[u1,la,lb] Gt[l1,l2,u2] +mathematica comment + 1/2 gtu[u1,u2] (- PD[gt[l1,l2],la,lb] + PD[gt[l1,la],l2,lb] +mathematica comment - PD[gt[la,lb],l1,l2] + PD[gt[l2,lb],l1,la]), +mathematica comment *) +mathematica blank +mathematica code fac1 -> IfThen[conformalMethod==CMW, -1/(2 phi), 1], +mathematica code cdphi[la] -> fac1 CDt[phi,la], +mathematica code fac2 -> IfThen[conformalMethod==CMW, 1/(2 phi^2), 0], +mathematica code cdphi2[la,lb] -> fac1 CDt[phi,la,lb] + fac2 CDt[phi,la] CDt[phi,lb], +mathematica blank +mathematica comment (* PRD 62, 044034 (2000), eqn. (15) *) +mathematica code Rphi[li,lj] -> - 2 cdphi2[lj,li] +mathematica code - 2 gt[li,lj] gtu[ul,un] cdphi2[ll,ln] +mathematica code + 4 cdphi[li] cdphi[lj] +mathematica code - 4 gt[li,lj] gtu[ul,un] cdphi[ln] cdphi[ll], +mathematica blank +mathematica comment (* ddetg[la] -> PD[e4phi detg,la], *) +mathematica code ddetg[la] -> e4phi ddetgt[la] + 4 detgt e4phi PD[phi,la], +mathematica comment (* TODO: check this equation, maybe simplify it by omitting ddetg *) +mathematica code G[ua,lb,lc] -> Gt[ua,lb,lc] +mathematica code + 1/(2 detg) (+ KD[ua,lb] ddetg[lc] + KD[ua,lc] ddetg[lb] +mathematica code - (1/3) g[lb,lc] gu[ua,ud] ddetg[ld]), +mathematica blank +mathematica code R[la,lb] -> + Rt[la,lb] + Rphi[la,lb], +mathematica blank +mathematica code IfCCZ4[ +mathematica code R[la,lb] -> R[la, lb] + (2/phi) (+ g[la,lc] Z[uc] PD[phi,lb] +mathematica code + g[lb,lc] Z[uc] PD[phi,la] - g[la,lb] Z[uc] PD[phi,lc]) +mathematica code + e4phi Z[uc] PD[gt[la,lb],lc] +mathematica code ], +mathematica blank +mathematica code trR -> gu[ua,ub] R[la,lb], +mathematica blank +mathematica comment (* K[la,lb] -> e4phi At[la,lb] + (1/3) g[la,lb] trK, *) +mathematica comment (* Km[ua,lb] -> gu[ua,uc] K[lc,lb], *) +mathematica code Atm[ua,lb] -> gtu[ua,uc] At[lc,lb], +mathematica blank +mathematica comment (* Matter terms *) +mathematica blank +mathematica comment (* rho = n^a n^b T_ab *) +mathematica code rho -> 1/alpha^2 (T00 - 2 beta[ui] T0[li] + beta[ui] beta[uj] T[li,lj]), +mathematica blank +mathematica comment (* S_i = -p^a_i n^b T_ab, where p^a_i = delta^a_i + n^a n_i *) +mathematica code S[li] -> -1/alpha (T0[li] - beta[uj] T[li,lj]), +mathematica blank +mathematica comment (* Constraints *) +mathematica blank +mathematica comment (* H -> trR - Km[ua,lb] Km[ub,la] + trK^2, *) +mathematica comment (* PRD 67, 084023 (2003), eqn. (19) *) +mathematica code H -> trR - Atm[ua,lb] Atm[ub,la] + (2/3) trK^2 - addMatter 16 Pi rho, +mathematica blank +mathematica comment (* gK[la,lb,lc] -> CD[K[la,lb],lc], *) +mathematica comment (* gK[la,lb,lc] -> + 4 e4phi PD[phi,lc] At[la,lb] + e4phi CD[At[la,lb],lc] +mathematica comment + (1/3) g[la,lb] PD[trK,lc], +mathematica comment M[la] -> gu[ub,uc] (gK[lc,la,lb] - gK[lc,lb,la]), *) +mathematica blank +mathematica code M[li] -> + gtu[uj,uk] (CDt[At[li,lj],lk] + 6 At[li,lj] cdphi[lk]) +mathematica code - (2/3) PD[trK,li] +mathematica code - addMatter 8 Pi S[li], +mathematica comment (* TODO: use PRD 67, 084023 (2003), eqn. (20) *) +mathematica blank +mathematica comment (* det gamma-tilde *) +mathematica code cS -> Log[detgt], +mathematica blank +mathematica comment (* Gamma constraint *) +mathematica code cXt[ua] -> gtu[ub,uc] Gt[ua,lb,lc] - Xt[ua], +mathematica blank +mathematica comment (* trace A-tilde *) +mathematica code cA -> gtu[ua,ub] At[la,lb] +mathematica code } +mathematica code }; +mathematica blank +mathematica code constraintsCalc1 = PartialCalculation[constraintsCalc, "1", +mathematica code {}, +mathematica code { +mathematica code H +mathematica code }]; +mathematica blank +mathematica code constraintsCalc2 = PartialCalculation[constraintsCalc, "2", +mathematica code {}, +mathematica code { +mathematica code M[li], +mathematica code cS, +mathematica code cXt[ua], +mathematica code cA +mathematica code }]; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Implementations *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code inheritedImplementations = +mathematica code Join[{"ADMBase"}, +mathematica code If [addMatter!=0, {"TmunuBase"}, {}]]; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Parameters *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code inheritedKeywordParameters = {}; +mathematica blank +mathematica code extendedKeywordParameters = +mathematica code { +mathematica code { +mathematica code Name -> "ADMBase::evolution_method", +mathematica code AllowedValues -> {thorn} +mathematica code }, +mathematica code { +mathematica code Name -> "ADMBase::lapse_evolution_method", +mathematica code AllowedValues -> {thorn} +mathematica code }, +mathematica code { +mathematica code Name -> "ADMBase::shift_evolution_method", +mathematica code AllowedValues -> {thorn} +mathematica code }, +mathematica code { +mathematica code Name -> "ADMBase::dtlapse_evolution_method", +mathematica code AllowedValues -> {thorn} +mathematica code }, +mathematica code { +mathematica code Name -> "ADMBase::dtshift_evolution_method", +mathematica code AllowedValues -> {thorn} +mathematica code } +mathematica code }; +mathematica blank +mathematica code keywordParameters = +mathematica code { +mathematica code { +mathematica code Name -> "my_initial_data", +mathematica comment (* Visibility -> "restricted", *) +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"ADMBase", "Minkowski"}, +mathematica code Default -> "ADMBase" +mathematica code }, +mathematica code { +mathematica code Name -> "my_initial_boundary_condition", +mathematica code Visibility -> "restricted", +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"none"}, +mathematica code Default -> "none" +mathematica code }, +mathematica code { +mathematica code Name -> "my_rhs_boundary_condition", +mathematica code Visibility -> "restricted", +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"none", "static", "radiative"}, +mathematica code Default -> "none" +mathematica code }, +mathematica code { +mathematica code Name -> "my_boundary_condition", +mathematica comment (* Visibility -> "restricted", *) +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"none", "Minkowski"}, +mathematica code Default -> "none" +mathematica code }, +mathematica code { +mathematica code Name -> "calculate_ADMBase_variables_at", +mathematica code Visibility -> "restricted", +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"MoL_PostStep", "CCTK_EVOL", "CCTK_ANALYSIS"}, +mathematica code Default -> "MoL_PostStep" +mathematica code }, +mathematica code { +mathematica code Name -> "UseSpatialBetaDriver_UNUSED", +mathematica code Visibility -> "restricted", +mathematica comment (* Description -> "ddd", *) +mathematica code AllowedValues -> {"no", "yes"}, +mathematica code Default -> "no" +mathematica code }, +mathematica code { +mathematica code Name -> "dt_lapse_shift_method", +mathematica code Description -> "Treatment of ADMBase dtlapse and dtshift", +mathematica code AllowedValues -> {"correct", +mathematica code "noLapseShiftAdvection" (* omit lapse and shift advection terms (faster) *) +mathematica code }, +mathematica code Default -> "correct" +mathematica code }, +mathematica code { +mathematica code Name -> "apply_dissipation", +mathematica code Description -> "Whether to apply dissipation to the RHSs", +mathematica code AllowedValues -> {"always", +mathematica code "never" (* yes and no keyword values confuse Cactus, and Kranc +mathematica comment doesn't support boolean parameters *) +mathematica code }, +mathematica code Default -> "never" +mathematica code }, +mathematica code { +mathematica code Name -> "RHS_split", +mathematica code Description -> "How to split RHS calculation", +mathematica code AllowedValues -> {"combined", +mathematica code "split At"}, +mathematica code Default -> "split At" +mathematica code }, +mathematica code { +mathematica code Name -> "advection_split", +mathematica code Description -> "How to split advection calculation", +mathematica code AllowedValues -> {"combined", +mathematica code "per variable"}, +mathematica code Default -> "combined" +mathematica code } +mathematica code }; +mathematica blank +mathematica code intParameters = +mathematica code { +mathematica code { +mathematica code Name -> harmonicN, +mathematica code Description -> "d/dt alpha = - f alpha^n K (harmonic=2, 1+log=1)", +mathematica code Default -> 2 +mathematica code }, +mathematica code { +mathematica code Name -> ShiftAlphaPower, +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> conformalMethod, +mathematica code Description -> "Treatment of conformal factor", +mathematica code AllowedValues -> {{Value -> "0", Description -> "phi method"}, +mathematica code {Value -> "1", Description -> "W method"}}, +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> fdOrder, +mathematica code Default -> derivOrder, +mathematica code AllowedValues -> {2,4,6,8} +mathematica code }, +mathematica code { +mathematica code Name -> harmonicShift, +mathematica code Description -> "Whether to use the harmonic shift", +mathematica code AllowedValues -> {{Value -> "0", Description -> "Gamma driver shift"}, +mathematica code {Value -> "1", Description -> "Harmonic shift"}}, +mathematica code Default -> 0 +mathematica code } +mathematica code }; +mathematica blank +mathematica code realParameters = +mathematica code { +mathematica code IfCCZ4[{ +mathematica code Name -> GammaShift, +mathematica code Description -> "Covariant shift term in Gamma", +mathematica code Default -> 0.5 +mathematica code }], +mathematica code IfCCZ4[{ +mathematica code Name -> dampk1, +mathematica code Description -> "CCZ4 damping term 1 for Theta and Z", +mathematica code Default -> 0 +mathematica code }], +mathematica code IfCCZ4[{ +mathematica code Name -> dampk2, +mathematica code Description -> "CCZ4 damping term 2 for Theta and Z", +mathematica code Default -> 0 +mathematica code }], +mathematica code { +mathematica code Name -> LapseACoeff, +mathematica code Description -> "Whether to evolve A in time", +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> harmonicF, +mathematica code Description -> "d/dt alpha = - f alpha^n K (harmonic=1, 1+log=2)", +mathematica code Default -> 1 +mathematica code }, +mathematica code { +mathematica code Name -> AlphaDriver, +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> ShiftBCoeff, +mathematica code Description -> "Whether to evolve B^i in time", +mathematica code Default -> 1 +mathematica code }, +mathematica code { +mathematica code Name -> ShiftGammaCoeff, +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> BetaDriver, +mathematica code Default -> 0 +mathematica code }, +mathematica code { +mathematica code Name -> LapseAdvectionCoeff, +mathematica code Description -> "Factor in front of the lapse advection terms in 1+log", +mathematica code Default -> 1 +mathematica code }, +mathematica code { +mathematica code Name -> ShiftAdvectionCoeff, +mathematica code Description -> "Factor in front of the shift advection terms in gamma driver", +mathematica code Default -> 1 +mathematica code }, +mathematica code { +mathematica code Name -> MinimumLapse, +mathematica code Description -> "Minimum value of the lapse function", +mathematica code Default -> -1 +mathematica code }, +mathematica code { +mathematica code Name -> SpatialBetaDriverRadius, +mathematica code Description -> "Radius at which the BetaDriver starts to be reduced", +mathematica code AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, +mathematica code Default -> 10^12 +mathematica code }, +mathematica code { +mathematica code Name -> SpatialShiftGammaCoeffRadius, +mathematica code Description -> "Radius at which the ShiftGammaCoefficient starts to be reduced", +mathematica code AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, +mathematica code Default -> 10^12 +mathematica code }, +mathematica code { +mathematica code Name -> EpsDiss, +mathematica code Description -> "Dissipation strength", +mathematica code AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, +mathematica code Default -> 0 +mathematica code } +mathematica code }; +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Construct the thorns *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica code calculations = +mathematica code Join[ +mathematica code { +mathematica code initialCalc, +mathematica code convertFromADMBaseCalc, +mathematica code initGammaCalc, +mathematica code convertFromADMBaseGammaCalc, +mathematica code evolCalc, +mathematica code evolCalc1, evolCalc2, +mathematica code dissCalc, +mathematica code advectCalc, +mathematica comment (*advectCalcs,*) +mathematica code initRHSCalc, +mathematica code RHSStaticBoundaryCalc, +mathematica comment (* RHSRadiativeBoundaryCalc, *) +mathematica code enforceCalc, +mathematica code boundaryCalc, +mathematica code convertToADMBaseCalc, +mathematica code convertToADMBaseDtLapseShiftCalc, +mathematica code convertToADMBaseDtLapseShiftBoundaryCalc, +mathematica code convertToADMBaseFakeDtLapseShiftCalc, +mathematica comment (* constraintsCalc, *) +mathematica code constraintsCalc1, constraintsCalc2 +mathematica code }, +mathematica code advectCalcs +mathematica comment (*dissCalcs*) +mathematica code ]; +mathematica blank +mathematica code CreateKrancThornTT [groups, ".", thorn, +mathematica code Calculations -> calculations, +mathematica code DeclaredGroups -> declaredGroupNames, +mathematica code PartialDerivatives -> derivatives, +mathematica code EvolutionTimelevels -> evolutionTimelevels, +mathematica code DefaultEvolutionTimelevels -> 3, +mathematica code UseJacobian -> True, +mathematica code UseLoopControl -> True, +mathematica code UseVectors -> useVectors, +mathematica code UseOpenCL -> useOpenCL, +mathematica code InheritedImplementations -> inheritedImplementations, +mathematica code InheritedKeywordParameters -> inheritedKeywordParameters, +mathematica code ExtendedKeywordParameters -> extendedKeywordParameters, +mathematica code KeywordParameters -> keywordParameters, +mathematica code IntParameters -> intParameters, +mathematica code RealParameters -> realParameters +mathematica code ]; +mathematica blank +mathematica code ]; +mathematica blank +mathematica blank +mathematica blank +mathematica comment (******************************************************************************) +mathematica comment (* Options *) +mathematica comment (******************************************************************************) +mathematica blank +mathematica comment (* These are the arguments to createComment: +mathematica comment - derivative order: 2, 4, 6, 8, ... +mathematica comment - useJacobian: False or True +mathematica comment - split upwind derivatives: False or True +mathematica comment - use vectorisation: False or True +mathematica comment - use OpenCL: False or True +mathematica comment - timelevels: 2 or 3 +mathematica comment ## (keep this at 3; this is better chosen with a run-time parameter) +mathematica comment - matter: 0 or 1 +mathematica comment ## (matter seems cheap; it should be always enabled) +mathematica comment - thorn base name +mathematica comment *) +mathematica blank +mathematica code createCode[4, False, True, True , False, 3, 1, "BSSN"]; +mathematica code createCode[4, False, True, False, False, 3, 1, "BSSN"]; +mathematica code createCode[4, False, True, True , True , 3, 1, "BSSN"]; +mathematica blank +mathematica code createCode[4, False, True, True , False, 3, 1, "CCZ4"]; +mathematica blank diff --git a/test/expected_dir/matlab1.m b/test/expected_dir/matlab1.m new file mode 100644 index 0000000..9c20b77 --- /dev/null +++ b/test/expected_dir/matlab1.m @@ -0,0 +1,56 @@ +matlab comment % PROGRAM theta_logistic.m +matlab comment % Calculates by simulation the probability that a population +matlab comment % following the theta logistic model and starting at Nc will fall +matlab comment % below the quasi-extinction threshold Nx at or before time tmax +matlab blank +matlab comment % SIMULATION PARAMETERS +matlab comment % for butterflies (Euphydryas editha bayensis) at Jasper Ridge (population C) +matlab blank +matlab code r=0.3458; % intrinsic rate of increase--Butterflies at Jasper Ridge +matlab code K=846.017; % carrying capacity +matlab code theta=1; % nonlinearity in density dependence +matlab code sigma2=1.1151; % environmental variance +matlab code Nc=94; % starting population size +matlab code Nx=20; % quasi-extinction threshold +matlab code tmax=20; % time horizon +matlab code NumReps=50000; % number of replicate population trajectories +matlab blank +matlab comment % SIMULATION CODE +matlab blank +matlab code sigma=sqrt(sigma2); +matlab code randn('state',sum(100*clock)); % seed the random number generator +matlab blank +matlab code N=Nc*ones(1,NumReps); % all NumRep populations start at Nc +matlab code NumExtant=NumReps; % all populations are initially extant +matlab code Extant=[NumExtant]; % vector for number of extant pops. vs. time +matlab blank +matlab code for t=1:tmax, % For each future time, +matlab code N=N.*exp( r*( 1-(N/K).^theta )... % the theta logistic model +matlab code + sigma*randn(1,NumExtant) ); % with random environmental effects. +matlab code for i=NumExtant:-1:1, % Then, looping over all extant populations, +matlab code if N(i)<=Nx, % if at or below quasi-extinction threshold, +matlab code N(i)=[]; % delete the population. +matlab code end; +matlab code end; +matlab code NumExtant=length(N); % Count remaining extant populations +matlab code Extant=[Extant NumExtant]; % and store the result. +matlab code end; +matlab blank +matlab comment % OUTPUT CODE +matlab comment % ComputeS quasi-extinction probability as the fraction of replicate +matlab comment % populations that have hit the threshold by each future time, +matlab comment % and plotS quasi-extinction probability vs. time +matlab blank +matlab code ProbExtinct=(NumReps-Extant)/NumReps; +matlab code plot([0:tmax],ProbExtinct) +matlab code xlabel('Years into the future'); +matlab code ylabel('Cumulative probability of quasi-extinction'); +matlab code axis([0 tmax 0 1]); +matlab blank +matlab comment % Integrate solution exactly % +matlab comment % Options=[]; +matlab comment % [T,true] = ode45(@logistic,[0,20],Nc,Options,r,K,theta); +matlab comment % subplot(1,2,2) +matlab comment % plot([1:tmax],P,'r.-',T,true,'g.-') +matlab blank +matlab comment ... This is a seriously old-school comment. \ No newline at end of file diff --git a/test/expected_dir/matlab1.m/matlab/blanks b/test/expected_dir/matlab1.m/matlab/blanks deleted file mode 100644 index f11c82a..0000000 --- a/test/expected_dir/matlab1.m/matlab/blanks +++ /dev/null @@ -1 +0,0 @@ -9 \ No newline at end of file diff --git a/test/expected_dir/matlab1.m/matlab/code b/test/expected_dir/matlab1.m/matlab/code deleted file mode 100644 index 0c0b7d9..0000000 --- a/test/expected_dir/matlab1.m/matlab/code +++ /dev/null @@ -1,29 +0,0 @@ -r=0.3458; % intrinsic rate of increase--Butterflies at Jasper Ridge -K=846.017; % carrying capacity -theta=1; % nonlinearity in density dependence -sigma2=1.1151; % environmental variance -Nc=94; % starting population size -Nx=20; % quasi-extinction threshold -tmax=20; % time horizon -NumReps=50000; % number of replicate population trajectories -sigma=sqrt(sigma2); -randn('state',sum(100*clock)); % seed the random number generator -N=Nc*ones(1,NumReps); % all NumRep populations start at Nc -NumExtant=NumReps; % all populations are initially extant -Extant=[NumExtant]; % vector for number of extant pops. vs. time -for t=1:tmax, % For each future time, -N=N.*exp( r*( 1-(N/K).^theta )... % the theta logistic model -+ sigma*randn(1,NumExtant) ); % with random environmental effects. -for i=NumExtant:-1:1, % Then, looping over all extant populations, -if N(i)<=Nx, % if at or below quasi-extinction threshold, -N(i)=[]; % delete the population. -end; -end; -NumExtant=length(N); % Count remaining extant populations -Extant=[Extant NumExtant]; % and store the result. -end; -ProbExtinct=(NumReps-Extant)/NumReps; -plot([0:tmax],ProbExtinct) -xlabel('Years into the future'); -ylabel('Cumulative probability of quasi-extinction'); -axis([0 tmax 0 1]); diff --git a/test/expected_dir/matlab1.m/matlab/comment b/test/expected_dir/matlab1.m/matlab/comment deleted file mode 100644 index e9dae13..0000000 --- a/test/expected_dir/matlab1.m/matlab/comment +++ /dev/null @@ -1,16 +0,0 @@ -% PROGRAM theta_logistic.m -% Calculates by simulation the probability that a population -% following the theta logistic model and starting at Nc will fall -% below the quasi-extinction threshold Nx at or before time tmax -% SIMULATION PARAMETERS -% for butterflies (Euphydryas editha bayensis) at Jasper Ridge (population C) -% SIMULATION CODE -% OUTPUT CODE -% ComputeS quasi-extinction probability as the fraction of replicate -% populations that have hit the threshold by each future time, -% and plotS quasi-extinction probability vs. time -% Integrate solution exactly % -% Options=[]; -% [T,true] = ode45(@logistic,[0,20],Nc,Options,r,K,theta); -% subplot(1,2,2) -% plot([1:tmax],P,'r.-',T,true,'g.-') diff --git a/test/expected_dir/metafont.mf b/test/expected_dir/metafont.mf new file mode 100644 index 0000000..a367226 --- /dev/null +++ b/test/expected_dir/metafont.mf @@ -0,0 +1,22 @@ +metafont comment % The (not really) first 20 or so lines from the plain METAFONT base +metafont blank +metafont comment % Unlimited copying and redistribution of this file are permitted as long +metafont comment % as this file is not modified. Modifications are permitted, but only if +metafont comment % the resulting file is not named plain.mf. +metafont blank +metafont code string base_name, base_version; base_name="plain"; base_version="2.71"; +metafont blank +metafont code message "Preloading the plain base, version "&base_version&": preliminaries,"; +metafont blank +metafont code delimiters (); % this makes parentheses behave like parentheses +metafont code def upto = step 1 until enddef; % syntactic sugar +metafont code def downto = step -1 until enddef; +metafont code def exitunless expr c = exitif not c enddef; +metafont code let relax = \; % ignore the word `relax', as in TeX +metafont code let \\ = \; % double relaxation is like single +metafont code def ]] = ] ] enddef; % right brackets should be loners +metafont code def -- = {curl 1}..{curl 1} enddef; +metafont code def --- = .. tension infinity .. enddef; +metafont code def ... = .. tension atleast 1 .. enddef; +metafont blank +metafont code def gobble primary g = enddef; def killtext text t = enddef; diff --git a/test/expected_dir/metafont.mf/metafont/blanks b/test/expected_dir/metafont.mf/metafont/blanks deleted file mode 100644 index 7813681..0000000 --- a/test/expected_dir/metafont.mf/metafont/blanks +++ /dev/null @@ -1 +0,0 @@ -5 \ No newline at end of file diff --git a/test/expected_dir/metafont.mf/metafont/code b/test/expected_dir/metafont.mf/metafont/code deleted file mode 100644 index f3f95b0..0000000 --- a/test/expected_dir/metafont.mf/metafont/code +++ /dev/null @@ -1,13 +0,0 @@ -string base_name, base_version; base_name="plain"; base_version="2.71"; -message "Preloading the plain base, version "&base_version&": preliminaries,"; -delimiters (); % this makes parentheses behave like parentheses -def upto = step 1 until enddef; % syntactic sugar -def downto = step -1 until enddef; -def exitunless expr c = exitif not c enddef; -let relax = \; % ignore the word `relax', as in TeX -let \\ = \; % double relaxation is like single -def ]] = ] ] enddef; % right brackets should be loners -def -- = {curl 1}..{curl 1} enddef; -def --- = .. tension infinity .. enddef; -def ... = .. tension atleast 1 .. enddef; -def gobble primary g = enddef; def killtext text t = enddef; diff --git a/test/expected_dir/metafont.mf/metafont/comment b/test/expected_dir/metafont.mf/metafont/comment deleted file mode 100644 index 06714e9..0000000 --- a/test/expected_dir/metafont.mf/metafont/comment +++ /dev/null @@ -1,4 +0,0 @@ -% The (not really) first 20 or so lines from the plain METAFONT base -% Unlimited copying and redistribution of this file are permitted as long -% as this file is not modified. Modifications are permitted, but only if -% the resulting file is not named plain.mf. diff --git a/test/expected_dir/metapost.mp b/test/expected_dir/metapost.mp new file mode 100644 index 0000000..0698dfb --- /dev/null +++ b/test/expected_dir/metapost.mp @@ -0,0 +1,62 @@ +metapost comment % Sample MetaPost with embedded LaTeX, used as unit test for ohcount +metapost comment % +metapost comment % The MetaPost code is taken of LaTeXLabels.mp from +metapost comment % the excellent MetaPost tutorial by Urs Oswald +metapost comment % http://www.ursoswald.ch/metapost/tutorial.html +metapost comment % +metapost code verbatimtex +tex comment %&latex +tex code \documentclass{article} +tex code \newcommand{\uB}{\upshape{B\'ezier}} % up: upright +tex code \newcommand{\iB}{\itshape{B\'ezier}} % it: italic +tex code \newcommand{\lB}{\slshape{B\'ezier}} % sl: slanted +tex code \newcommand{\cB}{\scshape{B\'ezier}} % sc: small caps +tex code \newfont{\cyr}{wncyr10} +tex code \begin{document} +metapost code etex +metapost blank +metapost code u:=25; % 25 = 25bp = 25 PostScript points = 30/72 in +metapost code wi:=10; % width in units u +metapost code he:=7; % height in units u +metapost code hoehe:=he*u; % height +metapost code breite:=wi*u; % width +metapost code picture lab; +metapost blank +metapost code beginfig(1) +metapost comment % --- Grid --- +metapost code for i=0 upto he: +metapost code draw (0, i*u)--(breite, i*u) withcolor .7white; +metapost code endfor +metapost code for j=0 upto wi: +metapost code draw (j*u, 0)--(j*u, hoehe) withcolor .7white; +metapost code endfor +metapost comment % --- End Grid --- +metapost blank +metapost code draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle; +metapost blank +metapost code for i=0 upto 5: +metapost code draw .5(u, u){dir 20i}..{dir 20i}(9.5u, 4u); +metapost code endfor +metapost blank +metapost code lab:=\thelabel( +metapost code btex +tex code \begin{tabular}{|r|l|l|l|l|} +tex code \hline +tex code \textbf{md} & upright & italic & slanted & smallcaps \\ +tex code \hline +tex code rm & \textrm{\uB} & \textrm{\iB} & \textrm{\lB} &\textrm{\cB} \\ +tex code sf & \textsf{\uB} & \textsf{\iB} &\textsf{\lB} &\textsf{\cB} \\ +tex code tt & \texttt{\uB} & \texttt{\iB} &\texttt{\lB} &\texttt{\cB} \\ +tex code \hline +tex code \end{tabular} +metapost code etex, +metapost code (.5breite, hoehe-1.5u) +metapost code ); +metapost blank +metapost code unfill bbox lab; +metapost code draw lab; +metapost blank +metapost code label.ulft(btex \cyr C\char24 rih, 08.09.2002 etex, (breite, 0)); +metapost code endfig; +metapost blank +metapost code end diff --git a/test/expected_dir/metapost.mp/metapost/blanks b/test/expected_dir/metapost.mp/metapost/blanks deleted file mode 100644 index 301160a..0000000 --- a/test/expected_dir/metapost.mp/metapost/blanks +++ /dev/null @@ -1 +0,0 @@ -8 \ No newline at end of file diff --git a/test/expected_dir/metapost.mp/metapost/code b/test/expected_dir/metapost.mp/metapost/code deleted file mode 100644 index 68ca6e4..0000000 --- a/test/expected_dir/metapost.mp/metapost/code +++ /dev/null @@ -1,29 +0,0 @@ -verbatimtex -etex -u:=25; % 25 = 25bp = 25 PostScript points = 30/72 in -wi:=10; % width in units u -he:=7; % height in units u -hoehe:=he*u; % height -breite:=wi*u; % width -picture lab; -beginfig(1) -for i=0 upto he: -draw (0, i*u)--(breite, i*u) withcolor .7white; -endfor -for j=0 upto wi: -draw (j*u, 0)--(j*u, hoehe) withcolor .7white; -endfor -draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle; -for i=0 upto 5: -draw .5(u, u){dir 20i}..{dir 20i}(9.5u, 4u); -endfor -lab:=\thelabel( -btex -etex, -(.5breite, hoehe-1.5u) -); -unfill bbox lab; -draw lab; -label.ulft(btex \cyr C\char24 rih, 08.09.2002 etex, (breite, 0)); -endfig; -end diff --git a/test/expected_dir/metapost.mp/metapost/comment b/test/expected_dir/metapost.mp/metapost/comment deleted file mode 100644 index 34d49cf..0000000 --- a/test/expected_dir/metapost.mp/metapost/comment +++ /dev/null @@ -1,8 +0,0 @@ -% Sample MetaPost with embedded LaTeX, used as unit test for ohcount -% -% The MetaPost code is taken of LaTeXLabels.mp from -% the excellent MetaPost tutorial by Urs Oswald -% http://www.ursoswald.ch/metapost/tutorial.html -% -% --- Grid --- -% --- End Grid --- diff --git a/test/expected_dir/metapost.mp/tex/blanks b/test/expected_dir/metapost.mp/tex/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/metapost.mp/tex/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/metapost.mp/tex/code b/test/expected_dir/metapost.mp/tex/code deleted file mode 100644 index 334d27a..0000000 --- a/test/expected_dir/metapost.mp/tex/code +++ /dev/null @@ -1,16 +0,0 @@ -\documentclass{article} -\newcommand{\uB}{\upshape{B\'ezier}} % up: upright -\newcommand{\iB}{\itshape{B\'ezier}} % it: italic -\newcommand{\lB}{\slshape{B\'ezier}} % sl: slanted -\newcommand{\cB}{\scshape{B\'ezier}} % sc: small caps -\newfont{\cyr}{wncyr10} -\begin{document} -\begin{tabular}{|r|l|l|l|l|} -\hline -\textbf{md} & upright & italic & slanted & smallcaps \\ -\hline -rm & \textrm{\uB} & \textrm{\iB} & \textrm{\lB} &\textrm{\cB} \\ -sf & \textsf{\uB} & \textsf{\iB} &\textsf{\lB} &\textsf{\cB} \\ -tt & \texttt{\uB} & \texttt{\iB} &\texttt{\lB} &\texttt{\cB} \\ -\hline -\end{tabular} diff --git a/test/expected_dir/metapost.mp/tex/comment b/test/expected_dir/metapost.mp/tex/comment deleted file mode 100644 index 68d8154..0000000 --- a/test/expected_dir/metapost.mp/tex/comment +++ /dev/null @@ -1 +0,0 @@ -%&latex diff --git a/test/expected_dir/mxml1.mxml b/test/expected_dir/mxml1.mxml new file mode 100644 index 0000000..3ef2c18 --- /dev/null +++ b/test/expected_dir/mxml1.mxml @@ -0,0 +1,26 @@ +mxml code +mxml blank +mxml code +mxml blank +mxml code +css blank +css code TextArea { +css code backgroundColor: #EEF5EE; +css code } +css blank +mxml code +mxml blank +mxml code +actionscript blank +actionscript code function copy() { +actionscript code destination.text=source.text +actionscript code } +actionscript blank +mxml code +mxml blank +mxml blank +mxml code +mxml code +mxml code +mxml blank +mxml code diff --git a/test/expected_dir/mxml1.mxml/actionscript/code b/test/expected_dir/mxml1.mxml/actionscript/code deleted file mode 100644 index d44d7a2..0000000 --- a/test/expected_dir/mxml1.mxml/actionscript/code +++ /dev/null @@ -1,3 +0,0 @@ -function copy() { -destination.text=source.text -} diff --git a/test/expected_dir/mxml1.mxml/css/code b/test/expected_dir/mxml1.mxml/css/code deleted file mode 100644 index cc0a23d..0000000 --- a/test/expected_dir/mxml1.mxml/css/code +++ /dev/null @@ -1,3 +0,0 @@ -TextArea { -backgroundColor: #EEF5EE; -} diff --git a/test/expected_dir/mxml1.mxml/mxml/code b/test/expected_dir/mxml1.mxml/mxml/code deleted file mode 100644 index 2664220..0000000 --- a/test/expected_dir/mxml1.mxml/mxml/code +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/test/expected_dir/nix.nix b/test/expected_dir/nix.nix new file mode 100644 index 0000000..db848ea --- /dev/null +++ b/test/expected_dir/nix.nix @@ -0,0 +1,24 @@ +nix code {pkgs,config}: +nix blank +nix comment # one line comment +nix code { +nix comment /* mulpiple line comment +nix comment foo = 21; +nix comment */ +nix code bar = " +shell comment #!/bin/sh +shell blank +shell code ls -la +shell comment # comment +shell code echo hello #comment +nix code "; +nix blank +nix code baz = '' +shell comment #!/bin/sh +shell blank +shell code ls -la +shell comment # comment +shell code echo hello #comment +nix code ''; +nix code nixHttp = [ http://nixos.org/ ]; +nix code } diff --git a/test/expected_dir/objj.j b/test/expected_dir/objj.j new file mode 100644 index 0000000..c2e598c --- /dev/null +++ b/test/expected_dir/objj.j @@ -0,0 +1,25 @@ +objective_j blank +objective_j code @import +objective_j code @import +objective_j blank +objective_j code @import "Superclass.j" +objective_j blank +objective_j comment /* +objective_j comment I'm commenting this class +objective_j comment */ +objective_j code @implementation Class : Superclass +objective_j code { +objective_j code var x @accessors; +objective_j code } +objective_j blank +objective_j code + (void)classMethod +objective_j code { +objective_j code return self; // this is a comment +objective_j code } +objective_j blank +objective_j code - (void)instanceMethod +objective_j code { +objective_j code return self; +objective_j code } +objective_j blank +objective_j code @end diff --git a/test/expected_dir/ocaml.ml b/test/expected_dir/ocaml.ml new file mode 100644 index 0000000..1171914 --- /dev/null +++ b/test/expected_dir/ocaml.ml @@ -0,0 +1,10 @@ +ocaml comment (** documentation *) +ocaml code print_string "Hello world!\n";; +ocaml comment (**/**) +ocaml comment (* extra comment *) +ocaml blank +ocaml comment (* multiline +ocaml comment comment*) +ocaml blank +ocaml comment (* recursion in (* a +ocaml comment comment *) to complicate things *) diff --git a/test/expected_dir/ocaml.ml/ocaml/blanks b/test/expected_dir/ocaml.ml/ocaml/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/ocaml.ml/ocaml/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/ocaml.ml/ocaml/code b/test/expected_dir/ocaml.ml/ocaml/code deleted file mode 100644 index bb7a2d2..0000000 --- a/test/expected_dir/ocaml.ml/ocaml/code +++ /dev/null @@ -1 +0,0 @@ -print_string "Hello world!\n";; diff --git a/test/expected_dir/ocaml.ml/ocaml/comment b/test/expected_dir/ocaml.ml/ocaml/comment deleted file mode 100644 index 8b700eb..0000000 --- a/test/expected_dir/ocaml.ml/ocaml/comment +++ /dev/null @@ -1,7 +0,0 @@ -(** documentation *) -(**/**) -(* extra comment *) -(* multiline -comment*) -(* recursion in (* a -comment *) to complicate things *) diff --git a/test/expected_dir/octave1.m b/test/expected_dir/octave1.m new file mode 100644 index 0000000..73977b0 --- /dev/null +++ b/test/expected_dir/octave1.m @@ -0,0 +1,301 @@ +octave comment ## Copyright (C) 2006, Regents of the University of California -*- mode: octave; -*- +octave comment ## +octave comment ## This program is free software distributed under the "modified" or +octave comment ## 3-clause BSD license appended to this file. +octave blank +octave code function varargout = toledolu(LU) +octave comment ## (*- texinfo -*) +octave comment ## @deftypefn{Function File} {[@var{L}, @var{U}, @var{P}]} = toledolu(@var{A}) +octave comment ## @deftypefnx{Function File} {[@var{L}, @var{U}]} = toledolu(@var{A}) +octave comment ## @deftypefnx{Function File} {@var{LUP}} = toledolu(@var{A}) +octave comment ## +octave comment ## Note: This returns a vector of indices for @var{P} and not a permutation +octave comment ## matrix. +octave comment ## +octave comment ## Factors @var{P}*@var{A}=@var{L}*@var{U} by Sivan Toledo's recursive factorization algorithm +octave comment ## with partial pivoting. While not as fast as the built-in LU, this +octave comment ## is significantly faster than the standard, unblocked algorithm +octave comment ## while remaining relatively easy to modify. +octave comment ## +octave comment ## See the help for lu for details about the other calling forms. +octave comment ## +octave comment ## For the algorithm, see +octave comment ## (* @itemize *) +octave comment ## (* @item *) +octave comment ## Toledo, Sivan. "Locality of reference in LU decomposition with +octave comment ## partial pivoting," SIAM J. of Matrix Analysis and Applications, +octave comment ## v18, n4, 1997. DOI: 10.1137/S0895479896297744 +octave comment ## @end itemize +octave comment ## +octave comment ## @seealso{lu} +octave comment ## +octave comment ## @end deftypefn +octave blank +octave comment ## Author: Jason Riedy +octave comment ## Keywords: linear-algebra, LU, factorization +octave comment ## Version: 0.2 +octave blank +octave comment ## This version isn't *quite* the same as Toledo's algorithm. I use a +octave comment ## doubling approach rather than using recursion. So non-power-of-2 +octave comment ## columns likely will be slightly different, but that shouldn't +octave comment ## affect the 'optimality' by more than a small constant factor. +octave blank +octave comment ## Also, I don't handle ncol > nrow optimally. The code factors the +octave comment ## first nrow columns and then updates the remaining ncol-nrow columns +octave comment ## with L. +octave blank +octave comment ## Might be worth eating the memory cost and tracking L separately. +octave comment ## The eye(n)+tril(LU,-1) could be expensive. +octave blank +octave code switch (nargout) +octave code case 0 +octave code return; +octave code case {1,2,3} +octave code otherwise +octave code usage ("[L,U,P] = lu(A), [P\\L, U] = lu(A), or (P\\L-I+U) = lu(A)"); +octave code endswitch +octave blank +octave code [nrow, ncol] = size(LU); +octave code nstep = min(nrow, ncol); +octave blank +octave code Pswap = zeros(nstep, 1); +octave blank +octave code for j=1:nstep, +octave code [pval, pind] = max(abs(LU(j:nrow, j))); +octave code pind = pind + j - 1; +octave code Pswap(j) = pind; +octave blank +octave code kahead = bitand(j, 1+bitcmp(j)); # last 1 bit in j +octave code kstart = j+1-kahead; +octave code kcols = min(kahead, nstep-j); +octave blank +octave code inds = kstart : j; +octave code Ucol = j+1 : j+kcols; +octave code Lrow = j+1 : nrow; +octave blank +octave comment ## permute just this column +octave code if (pind != j) +octave code tmp = LU(pind, j); +octave code LU(pind, j) = LU(j,j); +octave code LU(j,j) = tmp; +octave code endif +octave comment ## apply pending permutations to L +octave code n_to_piv = 1; +octave code ipivstart = j; +octave code jpivstart = j - n_to_piv; +octave code while (n_to_piv < kahead) +octave code pivcols = jpivstart : jpivstart+n_to_piv-1; +octave code for ipiv = ipivstart:j, +octave code pind = Pswap(ipiv); +octave code if (pind != ipiv) +octave code tmp = LU(pind, pivcols); +octave code LU(pind, pivcols) = LU(ipiv, pivcols); +octave code LU(ipiv, pivcols) = tmp; +octave code endif +octave code endfor +octave code ipivstart -= n_to_piv; +octave code n_to_piv *= 2; +octave code jpivstart -= n_to_piv; +octave code endwhile +octave blank +octave code if (LU(j,j) != 0.0 && !isnan(LU(j,j))), +octave code LU(j+1:nrow,j) /= LU(j,j); +octave code endif +octave blank +octave code if 0 == kcols, break; endif +octave blank +octave comment ## permute U to match perm already applied to L +octave code for k = inds, +octave code tmp = LU(Pswap(k), Ucol); +octave code LU(Pswap(k), Ucol) = LU(k, Ucol); +octave code LU(k, Ucol) = tmp; +octave code endfor +octave blank +octave code LU(inds, Ucol) = (eye(kahead) + tril(LU(inds, inds),-1)) \ LU(inds, Ucol); +octave code LU(Lrow, Ucol) -= LU(Lrow, inds) * LU(inds, Ucol); +octave code endfor +octave blank +octave comment ## handle pivot permutations in L out from the last step +octave code npived = bitand(nstep, 1+bitcmp(nstep)); +octave code j = nstep-npived; +octave code while (j > 0) +octave code n_to_piv = bitand(j, 1+bitcmp(j)); +octave blank +octave code pivcols = j-n_to_piv+1 : j; +octave code for ipiv = j+1:nstep, +octave code pind = Pswap(ipiv); +octave code if (pind != ipiv) +octave code tmp = LU(pind, pivcols); +octave code LU(pind, pivcols) = LU(ipiv, pivcols); +octave code LU(ipiv, pivcols) = tmp; +octave code endif +octave code endfor +octave blank +octave code j -= n_to_piv; +octave code endwhile +octave blank +octave code if (nrow < ncol), +octave code Ucol = nrow+1 : ncol; +octave code inds = 1:nrow; +octave code for k = inds, +octave code tmp = LU(Pswap(k), Ucol); +octave code LU(Pswap(k), Ucol) = LU(k, Ucol); +octave code LU(k, Ucol) = tmp; +octave code endfor +octave code LU(inds, Ucol) = (eye(nrow) + tril(LU(inds, inds),-1)) \ LU(inds, Ucol); +octave code endif +octave blank +octave code if (nargout == 1) +octave code varargout{1} = LU; +octave code return; +octave code endif +octave blank +octave code if nrow == ncol, +octave code L = eye(nrow) + tril(LU, -1); +octave code varargout{2} = triu(LU); +octave code elseif nrow < ncol, +octave code L = eye(nrow) + tril(LU, -1)(:,1:nrow); +octave code varargout{2} = triu(LU); +octave code else # nrow > ncol +octave code L = tril(LU, -1); +octave code for k=1:ncol, +octave code L(k,k) = 1; +octave code endfor +octave code varargout{2} = triu(LU)(1:ncol,:); +octave code endif +octave blank +octave code if (nargout == 2) +octave code for j = 1:nstep, +octave code pind = Pswap(j); +octave code tmp = L(pind,:); +octave code L(pind,:) = L(j,:); +octave code L(j,:) = tmp; +octave code endfor +octave code else # nargout == 3 +octave code P = 1:nrow; +octave code for j = 1:nstep, +octave code tmp = P(j); +octave code P(j) = P(Pswap(j)); +octave code P(Pswap(j)) = tmp; +octave code endfor +octave code varargout{3} = P; +octave code endif +octave code varargout{1} = L; +octave blank +octave code endfunction +octave blank +octave comment %!test +octave comment %! M = 15; +octave comment %! N = 15; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 16; +octave comment %! N = 16; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 17; +octave comment %! N = 17; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 8; +octave comment %! N = 17; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 8; +octave comment %! N = 15; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 7; +octave comment %! N = 17; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 7; +octave comment %! N = 15; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 17; +octave comment %! N = 8; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 15; +octave comment %! N = 8; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 17; +octave comment %! N = 7; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 15; +octave comment %! N = 7; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 31; +octave comment %! N = 17; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment %!test +octave comment %! M = 11; +octave comment %! N = 29; +octave comment %! A = rand(M,N); +octave comment %! [L,U,P] = toledolu(A); +octave comment %! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) +octave blank +octave comment ## Copyright (c) 2006, Regents of the University of California +octave comment ## All rights reserved. +octave comment ## Redistribution and use in source and binary forms, with or without +octave comment ## modification, are permitted provided that the following conditions are met: +octave comment ## +octave comment ## * Redistributions of source code must retain the above copyright +octave comment ## notice, this list of conditions and the following disclaimer. +octave comment ## * Redistributions in binary form must reproduce the above copyright +octave comment ## notice, this list of conditions and the following disclaimer in the +octave comment ## documentation and/or other materials provided with the distribution. +octave comment ## * Neither the name of the University of California, Berkeley nor the +octave comment ## names of its contributors may be used to endorse or promote products +octave comment ## derived from this software without specific prior written permission. +octave comment ## +octave comment ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY +octave comment ## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +octave comment ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +octave comment ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY +octave comment ## DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +octave comment ## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +octave comment ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +octave comment ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +octave comment ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +octave comment ## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/test/expected_dir/optimer b/test/expected_dir/optimer new file mode 100644 index 0000000..423c741 --- /dev/null +++ b/test/expected_dir/optimer @@ -0,0 +1,47 @@ +shell comment #!/bin/sh +shell comment # optimer – Masserer ordlistefilene til eit kjaptsøkt format. +shell comment # +shell comment # Copyright © 2008, 2009 Karl Ove Hufthammer . +shell comment # +shell comment # This file is part of Ordbanken. +shell comment # +shell comment # Ordbanken is free software: you can redistribute it and/or modify +shell comment # it under the terms of the GNU General Public License as published by +shell comment # the Free Software Foundation, either version 3 of the License, or +shell comment # (at your option) any later version. +shell comment # +shell comment # This program is distributed in the hope that it will be useful, +shell comment # but WITHOUT ANY WARRANTY; without even the implied warranty of +shell comment # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +shell comment # GNU General Public License for more details. +shell comment # +shell comment # You should have received a copy of the GNU General Public License +shell comment # along with this program. If not, see . +shell blank +shell comment # Utfør kommandoen pÃ¥ fila oppgjeven som førsteargument. +shell code fil=$1 +shell code echo $fil +shell blank +shell comment # Forklaring pÃ¥ filtreringskommandoane. +shell comment # grep: Filtrer vekk kommentarar (linjer som startar med «*»). +shell comment # fgrep: Filtrer unormerte ord. +shell comment # sed: Gjer om mellomrom i siste del av linja (der kodane er) til tabulatorar. +shell comment # (Korfor den kompliserte sed-kommandoen? Fordi kodane i utgangspunktet er +shell comment # skilde med mellomrom i staden for med tabulatorar. Dette ville ikkje vore +shell comment # noko problem om alle oppføringar besto av eitt ord, dÃ¥ «column» som +shell comment # standard handterer mellomrom og tabulatorar likt, men ordbanken har +shell comment # oppføringar som «pÃ¥ kryss og tvers», og dÃ¥ ville alle orda fÃ¥ kvar si +shell comment # kolonne (bruk «på» som oppslagsord for Ã¥ sjÃ¥ oppføringa). +shell comment # sed: Fjern kodar (pÃ¥ forma ) som inneheld tal (interne/uforstÃ¥elige kodar). +shell comment # sed: Fjern kodar («ord» utan <>) som startar med tal (interne/uforstÃ¥elige kodar). +shell comment # sed: Fjern talkoden pÃ¥ starten av linja. +shell comment # tr: SlÃ¥ saman etterfølgjande tabulatorar til éin. +shell comment # sort: Sorter fila (slik at oppslag med «look» gÃ¥r raskare). +shell code grep -v '^\*' $fil \ +shell code | fgrep -v "unormert" \ +shell code | sed -r 'h;s/^([^ ]+ [^ ]+ [^ ]+ )(.*)/\2/;s/ / /g;G;s/(.*)\n([^ ]+ [^ ]+ [^ ]+ )(.*)/\2\1/' \ +shell code | sed -r 's/<[^>]*[0-9][^>]*>+/ /g' \ +shell code | sed -r 's/ [0-9]+[^ ]*/ /g' \ +shell code | sed -r 's/^[0-9]+\s+//' \ +shell code | tr -s '\t' \ +shell code | LC_ALL=C sort > "${fil%.txt}.dat" diff --git a/test/expected_dir/pascal1.pas b/test/expected_dir/pascal1.pas new file mode 100644 index 0000000..1ca997c --- /dev/null +++ b/test/expected_dir/pascal1.pas @@ -0,0 +1,112 @@ +pascal comment {*************************************************************** +pascal comment * +pascal comment * Unit Name: pndefs +pascal comment * Purpose : Various Definitions and functions... +pascal comment * Author : Simon Steele +pascal comment * Copyright: This Source Code is Copyright © 1998-2000 Echo +pascal comment * Software and Simon Steele. Please read the license +pascal comment * agreement at www.pnotepad.org/press/psidx.html. +pascal comment **************************************************************} +pascal code unit pndefs; +pascal blank +pascal code interface +pascal blank +pascal code uses SysUtils; +pascal blank +pascal code function CreatePNFile(filename : string; Text : pChar) : Boolean; +pascal code function StripNewLines(aString: string): string; +pascal code procedure ConvertTypes(filename : string); +pascal blank +pascal code const strFileTypes : PChar = ('.txt'); +pascal code strOpenTypes : PChar = ('%2|Text files (*.txt)|*.txt|0|0|0|LOG files (*.log)|*.log|0|0|0|Executable Files (*.exe, *.com, *.dll)|*.exe;*.com;*.dll|0|0|0'); +pascal code sepChar = '|'; +pascal code verChar = '%'; +pascal code CurrFileVer = '2'; +pascal blank +pascal code implementation +pascal blank +pascal code function CreatePNFile(filename : string; Text : pChar) : Boolean; +pascal code var F : TextFile; +pascal code begin +pascal comment {$I-} +pascal code AssignFile(F, filename); +pascal code Rewrite(F); +pascal code Write(F, Text); +pascal code CloseFile(F); +pascal code If IOResult <> 0 Then Result := False +pascal code Else Result := True; +pascal comment {$I+} +pascal code end; +pascal blank +pascal code function StripNewLines(aString: string): string; +pascal code var i : longint; +pascal code begin +pascal code result := ''; +pascal code i := 1; +pascal code while i <= length(aString) do +pascal code begin +pascal code if aString[i] = #13 then result := result + ' ' else +pascal code if aString[i] <> #10 then result := result + aString[i]; +pascal code inc(i); +pascal code end; +pascal code end; +pascal blank +pascal code procedure ConvertTypes(filename : string); +pascal code var t : TextFile; +pascal code s : string; +pascal code ps : string; {part of string} +pascal code Part : integer; +pascal code ipos : integer; +pascal code OutStr : string; +pascal code const Desc = 1; +pascal code Files = 2; +pascal code Parser = 3; +pascal code Unix = 4; +pascal code begin +pascal comment // This assumes that it is being passed one of the old style type definition +pascal comment // files. We'll set the status on the main form to indicate this as well... +pascal code OutStr := VerChar + CurrFileVer; +pascal code if not fileexists(filename) then +pascal code begin +pascal code CreatePNFile(filename, strOpenTypes); +pascal code exit; +pascal code end; +pascal code Assignfile(t, FileName); +pascal code Reset(t); +pascal code repeat +pascal code Readln(t, s) +pascal code until (Length(s) > 0) or EOF(t); +pascal code CloseFile(t); +pascal code if s = '' then Exit; +pascal code part := Desc; +pascal code repeat +pascal code iPos := Pos(SepChar, s); +pascal code if (iPos = 0) and (Length(s) > 0) then +pascal code begin +pascal code ps := s; +pascal code s := ''; +pascal code end else +pascal code ps := Copy(s, 1, ipos - 1); +pascal code s := Copy(S, ipos + 1, Length(s)); +pascal code case part of +pascal code Desc : begin +pascal code OutStr := OutStr + SepChar + ps; +pascal code part := Files; +pascal code end; +pascal code Files : begin +pascal code OutStr := OutStr + SepChar + ps; +pascal code part := Parser; +pascal code end; +pascal code Parser : begin +pascal code OutStr := OutStr + SepChar + ps + SepChar + '0' + SepChar + '0'; +pascal code part := Desc; +pascal code end; +pascal code end; +pascal code until Length(s) < 1; +pascal code Assignfile(t, filename); +pascal code Rewrite(t); +pascal code Write(t, OutStr); +pascal code CloseFile(t); +pascal code end; +pascal blank +pascal code end. diff --git a/test/expected_dir/pascal1.pas/pascal/blanks b/test/expected_dir/pascal1.pas/pascal/blanks deleted file mode 100644 index f11c82a..0000000 --- a/test/expected_dir/pascal1.pas/pascal/blanks +++ /dev/null @@ -1 +0,0 @@ -9 \ No newline at end of file diff --git a/test/expected_dir/pascal1.pas/pascal/code b/test/expected_dir/pascal1.pas/pascal/code deleted file mode 100644 index 263e32f..0000000 --- a/test/expected_dir/pascal1.pas/pascal/code +++ /dev/null @@ -1,90 +0,0 @@ -unit pndefs; -interface -uses SysUtils; -function CreatePNFile(filename : string; Text : pChar) : Boolean; -function StripNewLines(aString: string): string; -procedure ConvertTypes(filename : string); -const strFileTypes : PChar = ('.txt'); -strOpenTypes : PChar = ('%2|Text files (*.txt)|*.txt|0|0|0|LOG files (*.log)|*.log|0|0|0|Executable Files (*.exe, *.com, *.dll)|*.exe;*.com;*.dll|0|0|0'); -sepChar = '|'; -verChar = '%'; -CurrFileVer = '2'; -implementation -function CreatePNFile(filename : string; Text : pChar) : Boolean; -var F : TextFile; -begin -AssignFile(F, filename); -Rewrite(F); -Write(F, Text); -CloseFile(F); -If IOResult <> 0 Then Result := False -Else Result := True; -end; -function StripNewLines(aString: string): string; -var i : longint; -begin -result := ''; -i := 1; -while i <= length(aString) do -begin -if aString[i] = #13 then result := result + ' ' else -if aString[i] <> #10 then result := result + aString[i]; -inc(i); -end; -end; -procedure ConvertTypes(filename : string); -var t : TextFile; -s : string; -ps : string; {part of string} -Part : integer; -ipos : integer; -OutStr : string; -const Desc = 1; -Files = 2; -Parser = 3; -Unix = 4; -begin -OutStr := VerChar + CurrFileVer; -if not fileexists(filename) then -begin -CreatePNFile(filename, strOpenTypes); -exit; -end; -Assignfile(t, FileName); -Reset(t); -repeat -Readln(t, s) -until (Length(s) > 0) or EOF(t); -CloseFile(t); -if s = '' then Exit; -part := Desc; -repeat -iPos := Pos(SepChar, s); -if (iPos = 0) and (Length(s) > 0) then -begin -ps := s; -s := ''; -end else -ps := Copy(s, 1, ipos - 1); -s := Copy(S, ipos + 1, Length(s)); -case part of -Desc : begin -OutStr := OutStr + SepChar + ps; -part := Files; -end; -Files : begin -OutStr := OutStr + SepChar + ps; -part := Parser; -end; -Parser : begin -OutStr := OutStr + SepChar + ps + SepChar + '0' + SepChar + '0'; -part := Desc; -end; -end; -until Length(s) < 1; -Assignfile(t, filename); -Rewrite(t); -Write(t, OutStr); -CloseFile(t); -end; -end. diff --git a/test/expected_dir/pascal1.pas/pascal/comment b/test/expected_dir/pascal1.pas/pascal/comment deleted file mode 100644 index de8ff05..0000000 --- a/test/expected_dir/pascal1.pas/pascal/comment +++ /dev/null @@ -1,13 +0,0 @@ -{*************************************************************** -* -* Unit Name: pndefs -* Purpose : Various Definitions and functions... -* Author : Simon Steele -* Copyright: This Source Code is Copyright © 1998-2000 Echo -* Software and Simon Steele. Please read the license -* agreement at www.pnotepad.org/press/psidx.html. -**************************************************************} -{$I-} -{$I+} -// This assumes that it is being passed one of the old style type definition -// files. We'll set the status on the main form to indicate this as well... diff --git a/test/expected_dir/pascal2.pp b/test/expected_dir/pascal2.pp new file mode 100644 index 0000000..1ca997c --- /dev/null +++ b/test/expected_dir/pascal2.pp @@ -0,0 +1,112 @@ +pascal comment {*************************************************************** +pascal comment * +pascal comment * Unit Name: pndefs +pascal comment * Purpose : Various Definitions and functions... +pascal comment * Author : Simon Steele +pascal comment * Copyright: This Source Code is Copyright © 1998-2000 Echo +pascal comment * Software and Simon Steele. Please read the license +pascal comment * agreement at www.pnotepad.org/press/psidx.html. +pascal comment **************************************************************} +pascal code unit pndefs; +pascal blank +pascal code interface +pascal blank +pascal code uses SysUtils; +pascal blank +pascal code function CreatePNFile(filename : string; Text : pChar) : Boolean; +pascal code function StripNewLines(aString: string): string; +pascal code procedure ConvertTypes(filename : string); +pascal blank +pascal code const strFileTypes : PChar = ('.txt'); +pascal code strOpenTypes : PChar = ('%2|Text files (*.txt)|*.txt|0|0|0|LOG files (*.log)|*.log|0|0|0|Executable Files (*.exe, *.com, *.dll)|*.exe;*.com;*.dll|0|0|0'); +pascal code sepChar = '|'; +pascal code verChar = '%'; +pascal code CurrFileVer = '2'; +pascal blank +pascal code implementation +pascal blank +pascal code function CreatePNFile(filename : string; Text : pChar) : Boolean; +pascal code var F : TextFile; +pascal code begin +pascal comment {$I-} +pascal code AssignFile(F, filename); +pascal code Rewrite(F); +pascal code Write(F, Text); +pascal code CloseFile(F); +pascal code If IOResult <> 0 Then Result := False +pascal code Else Result := True; +pascal comment {$I+} +pascal code end; +pascal blank +pascal code function StripNewLines(aString: string): string; +pascal code var i : longint; +pascal code begin +pascal code result := ''; +pascal code i := 1; +pascal code while i <= length(aString) do +pascal code begin +pascal code if aString[i] = #13 then result := result + ' ' else +pascal code if aString[i] <> #10 then result := result + aString[i]; +pascal code inc(i); +pascal code end; +pascal code end; +pascal blank +pascal code procedure ConvertTypes(filename : string); +pascal code var t : TextFile; +pascal code s : string; +pascal code ps : string; {part of string} +pascal code Part : integer; +pascal code ipos : integer; +pascal code OutStr : string; +pascal code const Desc = 1; +pascal code Files = 2; +pascal code Parser = 3; +pascal code Unix = 4; +pascal code begin +pascal comment // This assumes that it is being passed one of the old style type definition +pascal comment // files. We'll set the status on the main form to indicate this as well... +pascal code OutStr := VerChar + CurrFileVer; +pascal code if not fileexists(filename) then +pascal code begin +pascal code CreatePNFile(filename, strOpenTypes); +pascal code exit; +pascal code end; +pascal code Assignfile(t, FileName); +pascal code Reset(t); +pascal code repeat +pascal code Readln(t, s) +pascal code until (Length(s) > 0) or EOF(t); +pascal code CloseFile(t); +pascal code if s = '' then Exit; +pascal code part := Desc; +pascal code repeat +pascal code iPos := Pos(SepChar, s); +pascal code if (iPos = 0) and (Length(s) > 0) then +pascal code begin +pascal code ps := s; +pascal code s := ''; +pascal code end else +pascal code ps := Copy(s, 1, ipos - 1); +pascal code s := Copy(S, ipos + 1, Length(s)); +pascal code case part of +pascal code Desc : begin +pascal code OutStr := OutStr + SepChar + ps; +pascal code part := Files; +pascal code end; +pascal code Files : begin +pascal code OutStr := OutStr + SepChar + ps; +pascal code part := Parser; +pascal code end; +pascal code Parser : begin +pascal code OutStr := OutStr + SepChar + ps + SepChar + '0' + SepChar + '0'; +pascal code part := Desc; +pascal code end; +pascal code end; +pascal code until Length(s) < 1; +pascal code Assignfile(t, filename); +pascal code Rewrite(t); +pascal code Write(t, OutStr); +pascal code CloseFile(t); +pascal code end; +pascal blank +pascal code end. diff --git a/test/expected_dir/pascal2.pp/pascal/blanks b/test/expected_dir/pascal2.pp/pascal/blanks deleted file mode 100644 index f11c82a..0000000 --- a/test/expected_dir/pascal2.pp/pascal/blanks +++ /dev/null @@ -1 +0,0 @@ -9 \ No newline at end of file diff --git a/test/expected_dir/pascal2.pp/pascal/code b/test/expected_dir/pascal2.pp/pascal/code deleted file mode 100644 index 263e32f..0000000 --- a/test/expected_dir/pascal2.pp/pascal/code +++ /dev/null @@ -1,90 +0,0 @@ -unit pndefs; -interface -uses SysUtils; -function CreatePNFile(filename : string; Text : pChar) : Boolean; -function StripNewLines(aString: string): string; -procedure ConvertTypes(filename : string); -const strFileTypes : PChar = ('.txt'); -strOpenTypes : PChar = ('%2|Text files (*.txt)|*.txt|0|0|0|LOG files (*.log)|*.log|0|0|0|Executable Files (*.exe, *.com, *.dll)|*.exe;*.com;*.dll|0|0|0'); -sepChar = '|'; -verChar = '%'; -CurrFileVer = '2'; -implementation -function CreatePNFile(filename : string; Text : pChar) : Boolean; -var F : TextFile; -begin -AssignFile(F, filename); -Rewrite(F); -Write(F, Text); -CloseFile(F); -If IOResult <> 0 Then Result := False -Else Result := True; -end; -function StripNewLines(aString: string): string; -var i : longint; -begin -result := ''; -i := 1; -while i <= length(aString) do -begin -if aString[i] = #13 then result := result + ' ' else -if aString[i] <> #10 then result := result + aString[i]; -inc(i); -end; -end; -procedure ConvertTypes(filename : string); -var t : TextFile; -s : string; -ps : string; {part of string} -Part : integer; -ipos : integer; -OutStr : string; -const Desc = 1; -Files = 2; -Parser = 3; -Unix = 4; -begin -OutStr := VerChar + CurrFileVer; -if not fileexists(filename) then -begin -CreatePNFile(filename, strOpenTypes); -exit; -end; -Assignfile(t, FileName); -Reset(t); -repeat -Readln(t, s) -until (Length(s) > 0) or EOF(t); -CloseFile(t); -if s = '' then Exit; -part := Desc; -repeat -iPos := Pos(SepChar, s); -if (iPos = 0) and (Length(s) > 0) then -begin -ps := s; -s := ''; -end else -ps := Copy(s, 1, ipos - 1); -s := Copy(S, ipos + 1, Length(s)); -case part of -Desc : begin -OutStr := OutStr + SepChar + ps; -part := Files; -end; -Files : begin -OutStr := OutStr + SepChar + ps; -part := Parser; -end; -Parser : begin -OutStr := OutStr + SepChar + ps + SepChar + '0' + SepChar + '0'; -part := Desc; -end; -end; -until Length(s) < 1; -Assignfile(t, filename); -Rewrite(t); -Write(t, OutStr); -CloseFile(t); -end; -end. diff --git a/test/expected_dir/pascal2.pp/pascal/comment b/test/expected_dir/pascal2.pp/pascal/comment deleted file mode 100644 index de8ff05..0000000 --- a/test/expected_dir/pascal2.pp/pascal/comment +++ /dev/null @@ -1,13 +0,0 @@ -{*************************************************************** -* -* Unit Name: pndefs -* Purpose : Various Definitions and functions... -* Author : Simon Steele -* Copyright: This Source Code is Copyright © 1998-2000 Echo -* Software and Simon Steele. Please read the license -* agreement at www.pnotepad.org/press/psidx.html. -**************************************************************} -{$I-} -{$I+} -// This assumes that it is being passed one of the old style type definition -// files. We'll set the status on the main form to indicate this as well... diff --git a/test/expected_dir/perl.cgi b/test/expected_dir/perl.cgi new file mode 100644 index 0000000..c5f2bf9 --- /dev/null +++ b/test/expected_dir/perl.cgi @@ -0,0 +1,66 @@ +perl comment #!/usr/bin/perl -w +perl blank +perl comment # ajaxCheckbox.pl - a script to test Ajax functionality +perl blank +perl code use strict; +perl code use CGI qw/:standard/; +perl code use CGI::Ajax; +perl code use DBI; +perl blank +perl comment # --- database authenication +perl code my $dbh = do 'db.inc'; +perl blank +perl code my $query = q{ SELECT project.project_id, project.name, project.phase, prio.prio, +perl code HEX((255 - prio.prio)) AS hex, begun, tags +perl code FROM project JOIN prio +perl code ON (project.project_id = prio.project_id) +perl code WHERE completed < 1 +perl code ORDER BY prio.prio DESC LIMIT 3}; +perl blank +perl code my $sth = $dbh->prepare($query); +perl code $sth->execute(); +perl code my $result = $dbh->selectall_arrayref($sth); +perl blank +perl code my $cgi = new CGI; +perl code my $pjx = new CGI::Ajax( 'toStruck' => \&perl_func ); +perl code print $pjx->build_html( $cgi, \&Show_HTML); +perl blank +perl code sub Show_HTML { +perl blank +perl code use CGI qw/:standard/; +perl blank +perl code my $html = < +perl code +perl code +perl code This is the lastest source version +perl code +perl code +perl code +perl code

Carrot Queue

Priority List  |   +perl code Add a listing  |  

Project listing

+perl code HEAD +perl blank +perl code foreach my $row (@$result) { +perl code $html .= ""; +perl code $html .= "
" . @$row[1] . "

"; +perl code } +perl blank +perl comment # you can append stuff to the HTML this way +perl code $html .= ""; +perl blank +perl code return $html; +perl code } +perl blank +perl code sub perl_func { +perl code my $input=shift; +perl blank +perl comment # if onClick the change the style +perl code if ($input eq "ON") { +perl code $input=""; +perl code } else { +perl code $input =""; +perl code } +perl code } diff --git a/test/expected_dir/perl.cgi/perl/blanks b/test/expected_dir/perl.cgi/perl/blanks deleted file mode 100644 index da2d398..0000000 --- a/test/expected_dir/perl.cgi/perl/blanks +++ /dev/null @@ -1 +0,0 @@ -14 \ No newline at end of file diff --git a/test/expected_dir/perl.cgi/perl/code b/test/expected_dir/perl.cgi/perl/code deleted file mode 100644 index 4957a35..0000000 --- a/test/expected_dir/perl.cgi/perl/code +++ /dev/null @@ -1,47 +0,0 @@ -use strict; -use CGI qw/:standard/; -use CGI::Ajax; -use DBI; -my $dbh = do 'db.inc'; -my $query = q{ SELECT project.project_id, project.name, project.phase, prio.prio, -HEX((255 - prio.prio)) AS hex, begun, tags -FROM project JOIN prio -ON (project.project_id = prio.project_id) -WHERE completed < 1 -ORDER BY prio.prio DESC LIMIT 3}; -my $sth = $dbh->prepare($query); -$sth->execute(); -my $result = $dbh->selectall_arrayref($sth); -my $cgi = new CGI; -my $pjx = new CGI::Ajax( 'toStruck' => \&perl_func ); -print $pjx->build_html( $cgi, \&Show_HTML); -sub Show_HTML { -use CGI qw/:standard/; -my $html = < - - -This is the lastest source version - - - -

Carrot Queue

Priority List  |   -Add a listing  |  

Project listing

-HEAD -foreach my $row (@$result) { -$html .= ""; -$html .= "
" . @$row[1] . "

"; -} -$html .= ""; -return $html; -} -sub perl_func { -my $input=shift; -if ($input eq "ON") { -$input=""; -} else { -$input =""; -} -} diff --git a/test/expected_dir/perl.cgi/perl/comment b/test/expected_dir/perl.cgi/perl/comment deleted file mode 100644 index 8844721..0000000 --- a/test/expected_dir/perl.cgi/perl/comment +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/perl -w -# ajaxCheckbox.pl - a script to test Ajax functionality -# --- database authenication -# you can append stuff to the HTML this way -# if onClick the change the style diff --git a/test/expected_dir/perl1.pl b/test/expected_dir/perl1.pl new file mode 100644 index 0000000..60744e5 --- /dev/null +++ b/test/expected_dir/perl1.pl @@ -0,0 +1,72 @@ +perl comment #!/usr/bin/perl +perl comment # Conserve bandwidth - put a copy of Dilbert on your intranet. +perl comment # Run every morning with cron - after about 7am Eastern +perl comment ######################################################## +perl code use Time::ParseDate; +perl code use Time::CTime; +perl code use LWP::Simple; +perl blank +perl comment # Where do you want the image put? +perl code $dir="/usr/local/etc/httpd/htdocs/Dilbert"; +perl comment # $dir = "c:/httpd/htdocs/Dilbert"; +perl code $location ="$dir/dilbert.gif"; +perl blank +perl code $_ = get("http://www.unitedmedia.com/comics/dilbert/index.html"); +perl blank +perl comment # These next 4 lines will change every time they change the +perl comment # page layout on the Dilbert site. Check back on my web site +perl comment # if things suddenly stop working +perl code s/^.*strip_left\.gif//s; +perl code s/^.*?HREF=\"//s; +perl code s/\">.*$//s; +perl code $line = "http://www.unitedmedia.com" . $_; +perl blank +perl comment # Back up yesterday's image: +perl comment # get the number +perl code open (ID,"$dir/id"); +perl code $id=; +perl code close ID; +perl blank +perl code $id++; +perl code $id=~s/\n$//; +perl code `mv $location $dir/dilbert.$id.gif`; +perl comment # If you're using this on NT, you may want to replace 'mv' +perl comment # with 'move'. +perl blank +perl code open (ID,">$dir/id"); +perl code print ID "$id"; +perl code close ID; +perl blank +perl comment # Now get the actual image +perl code $_ = get($line); +perl blank +perl code open (FILE, ">$location"); +perl code binmode FILE; # Important for NT +perl code print FILE; +perl code close FILE; +perl blank +perl comment # Now I want to update the index.html file +perl code open (FILE, "$dir/index.html"); +perl code @index=; +perl code close FILE; +perl blank +perl code $yesterday = parsedate('yesterday'); +perl code $printdate = strftime('%a, %b %d', localtime($yesterday)); +perl blank +perl code open (FILE, ">$dir/index.html"); +perl code for (@index) { +perl code if (/INSERT HERE/) { +perl code print FILE "$_"; +perl code print FILE "$printdate\n"; +perl code if (($id % 5) == 0) {print FILE "\n"} +perl code } +perl code else {print FILE "$_"}; +perl code } # End for +perl code close FILE; +perl blank +perl comment # Start with an index.html file containing ... +perl comment # +perl comment # +perl comment #
+perl comment # ... +perl comment # And whatever else you want on the page. diff --git a/test/expected_dir/perl1.pl/perl/blanks b/test/expected_dir/perl1.pl/perl/blanks deleted file mode 100644 index 3cacc0b..0000000 --- a/test/expected_dir/perl1.pl/perl/blanks +++ /dev/null @@ -1 +0,0 @@ -12 \ No newline at end of file diff --git a/test/expected_dir/perl1.pl/perl/code b/test/expected_dir/perl1.pl/perl/code deleted file mode 100644 index 768585f..0000000 --- a/test/expected_dir/perl1.pl/perl/code +++ /dev/null @@ -1,45 +0,0 @@ -use Time::ParseDate; -use Time::CTime; -use LWP::Simple; -$dir="/usr/local/etc/httpd/htdocs/Dilbert"; -$location ="$dir/dilbert.gif"; -$_ = get("http://www.unitedmedia.com/comics/dilbert/index.html"); -s/^.*strip_left\.gif//s; -s/^.*?HREF=\"//s; -s/\">.*$//s; -$line = "http://www.unitedmedia.com" . $_; -# Back up yesterday's image: -# get the number -open (ID,"$dir/id"); -$id=; -close ID; -$id++; -$id=~s/\n$//; -`mv $location $dir/dilbert.$id.gif`; -# If you're using this on NT, you may want to replace 'mv' -# with 'move'. -open (ID,">$dir/id"); -print ID "$id"; -close ID; -# Now get the actual image -$_ = get($line); -open (FILE, ">$location"); -binmode FILE; # Important for NT -print FILE; -close FILE; -# Now I want to update the index.html file -open (FILE, "$dir/index.html"); -@index=; -close FILE; -$yesterday = parsedate('yesterday'); -$printdate = strftime('%a, %b %d', localtime($yesterday)); -open (FILE, ">$dir/index.html"); -for (@index) { -if (/INSERT HERE/) { -print FILE "$_"; -print FILE "$printdate\n"; -if (($id % 5) == 0) {print FILE "\n"} -} -else {print FILE "$_"}; -} # End for -close FILE; diff --git a/test/expected_dir/perl1.pl/perl/comment b/test/expected_dir/perl1.pl/perl/comment deleted file mode 100644 index d9fab5e..0000000 --- a/test/expected_dir/perl1.pl/perl/comment +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/perl -# Conserve bandwidth - put a copy of Dilbert on your intranet. -# Run every morning with cron - after about 7am Eastern -######################################################## -# Where do you want the image put? -# $dir = "c:/httpd/htdocs/Dilbert"; -# These next 4 lines will change every time they change the -# page layout on the Dilbert site. Check back on my web site -# if things suddenly stop working -# Start with an index.html file containing ... -# -# -#
-# ... -# And whatever else you want on the page. diff --git a/test/expected_dir/perl_module.pm b/test/expected_dir/perl_module.pm new file mode 100644 index 0000000..f62cbe3 --- /dev/null +++ b/test/expected_dir/perl_module.pm @@ -0,0 +1,1191 @@ +perl code package PAR::Dist; +perl code require Exporter; +perl code use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK/; +perl blank +perl code $VERSION = '0.29'; +perl code @ISA = 'Exporter'; +perl code @EXPORT = qw/ +perl code blib_to_par +perl code install_par +perl code uninstall_par +perl code sign_par +perl code verify_par +perl code merge_par +perl code remove_man +perl code get_meta +perl code generate_blib_stub +perl code /; +perl blank +perl code @EXPORT_OK = qw/ +perl code parse_dist_name +perl code contains_binaries +perl code /; +perl blank +perl code use strict; +perl code use Carp qw/carp croak/; +perl code use File::Spec; +perl blank +perl comment =head1 NAME +perl blank +perl comment PAR::Dist - Create and manipulate PAR distributions +perl blank +perl comment =head1 VERSION +perl blank +perl comment This document describes version 0.29 of PAR::Dist, released Feb 6, 2008. +perl blank +perl comment =head1 SYNOPSIS +perl blank +perl comment As a shell command: +perl blank +perl comment % perl -MPAR::Dist -eblib_to_par +perl blank +perl comment In programs: +perl blank +perl comment use PAR::Dist; +perl blank +perl comment my $dist = blib_to_par(); # make a PAR file using ./blib/ +perl comment install_par($dist); # install it into the system +perl comment uninstall_par($dist); # uninstall it from the system +perl comment sign_par($dist); # sign it using Module::Signature +perl comment verify_par($dist); # verify it using Module::Signature +perl blank +perl comment install_par("http://foo.com/DBI-1.37-MSWin32-5.8.0.par"); # works too +perl comment install_par("http://foo.com/DBI-1.37"); # auto-appends archname + perlver +perl comment install_par("cpan://SMUELLER/PAR-Packer-0.975"); # uses CPAN author directory +perl blank +perl comment =head1 DESCRIPTION +perl blank +perl comment This module creates and manipulates I. They are +perl comment architecture-specific B files, containing everything under F +perl comment of CPAN distributions after their C or C stage, a +perl comment F describing metadata of the original CPAN distribution, +perl comment and a F detailing all files within it. Digitally signed PAR +perl comment distributions will also contain a F file. +perl blank +perl comment The naming convention for such distributions is: +perl blank +perl comment $NAME-$VERSION-$ARCH-$PERL_VERSION.par +perl blank +perl comment For example, C corresponds to the +perl comment 0.01 release of C on CPAN, built for perl 5.8.0 running on +perl comment C. +perl blank +perl comment =head1 FUNCTIONS +perl blank +perl comment Several functions are exported by default. Unless otherwise noted, +perl comment they can take either a hash of +perl comment named arguments, a single argument (taken as C<$path> by C +perl comment and C<$dist> by other functions), or no arguments (in which case +perl comment the first PAR file in the current directory is used). +perl blank +perl comment Therefore, under a directory containing only a single F, all +perl comment invocations below are equivalent: +perl blank +perl comment % perl -MPAR::Dist -e"install_par( dist => 'test.par' )" +perl comment % perl -MPAR::Dist -e"install_par( 'test.par' )" +perl comment % perl -MPAR::Dist -einstall_par; +perl blank +perl comment If C<$dist> resembles a URL, C is called to mirror it +perl comment locally under C<$ENV{PAR_TEMP}> (or C<$TEMP/par/> if unspecified), and the +perl comment function will act on the fetched local file instead. If the URL begins +perl comment with C, it will be expanded automatically to the author's CPAN +perl comment directory (e.g. C). +perl blank +perl comment If C<$dist> does not have a file extension beginning with a letter or +perl comment underscore, a dash and C<$suffix> ($ARCH-$PERL_VERSION.par by default) +perl comment will be appended to it. +perl blank +perl comment =head2 blib_to_par +perl blank +perl comment Takes key/value pairs as parameters or a single parameter indicating the +perl comment path that contains the F subdirectory. +perl blank +perl comment Builds a PAR distribution from the F subdirectory under C, or +perl comment under the current directory if unspecified. If F does not exist, +perl comment it automatically runs F, F, F or F to +perl comment create it. +perl blank +perl comment Returns the filename or the generated PAR distribution. +perl blank +perl comment Valid parameters are: +perl blank +perl comment =over 2 +perl blank +perl comment =item path +perl blank +perl comment Sets the path which contains the F subdirectory from which the PAR +perl comment distribution will be generated. +perl blank +perl comment =item name, version, suffix +perl blank +perl comment These attributes set the name, version and platform specific suffix +perl comment of the distribution. Name and version can be automatically +perl comment determined from the distributions F or F files. +perl blank +perl comment The suffix is generated from your architecture name and your version of +perl comment perl by default. +perl blank +perl comment =item dist +perl blank +perl comment The output filename for the PAR distribution. +perl blank +perl comment =back +perl blank +perl comment =cut +perl blank +perl code sub blib_to_par { +perl code @_ = (path => @_) if @_ == 1; +perl blank +perl code my %args = @_; +perl code require Config; +perl blank +perl blank +perl comment # don't use 'my $foo ... if ...' it creates a static variable! +perl code my $dist; +perl code my $path = $args{path}; +perl code $dist = File::Spec->rel2abs($args{dist}) if $args{dist}; +perl code my $name = $args{name}; +perl code my $version = $args{version}; +perl code my $suffix = $args{suffix} || "$Config::Config{archname}-$Config::Config{version}.par"; +perl code my $cwd; +perl blank +perl code if (defined $path) { +perl code require Cwd; +perl code $cwd = Cwd::cwd(); +perl code chdir $path; +perl code } +perl blank +perl code _build_blib() unless -d "blib"; +perl blank +perl code my @files; +perl code open MANIFEST, ">", File::Spec->catfile("blib", "MANIFEST") or die $!; +perl code open META, ">", File::Spec->catfile("blib", "META.yml") or die $!; +perl blank +perl code require File::Find; +perl code File::Find::find( sub { +perl code next unless $File::Find::name; +perl code (-r && !-d) and push ( @files, substr($File::Find::name, 5) ); +perl code } , 'blib' ); +perl blank +perl code print MANIFEST join( +perl code "\n", +perl code ' ', +perl code (sort @files), +perl code q( # ) +perl code ); +perl code close MANIFEST; +perl blank +perl code if (open(OLD_META, "META.yml")) { +perl code while () { +perl code if (/^distribution_type:/) { +perl code print META "distribution_type: par\n"; +perl code } +perl code else { +perl code print META $_; +perl code } +perl blank +perl code if (/^name:\s+(.*)/) { +perl code $name ||= $1; +perl code $name =~ s/::/-/g; +perl code } +perl code elsif (/^version:\s+.*Module::Build::Version/) { +perl code while () { +perl code /^\s+original:\s+(.*)/ or next; +perl code $version ||= $1; +perl code last; +perl code } +perl code } +perl code elsif (/^version:\s+(.*)/) { +perl code $version ||= $1; +perl code } +perl code } +perl code close OLD_META; +perl code close META; +perl code } +perl blank +perl code if ((!$name or !$version) and open(MAKEFILE, "Makefile")) { +perl code while () { +perl code if (/^DISTNAME\s+=\s+(.*)$/) { +perl code $name ||= $1; +perl code } +perl code elsif (/^VERSION\s+=\s+(.*)$/) { +perl code $version ||= $1; +perl code } +perl code } +perl code } +perl blank +perl code if (not defined($name) or not defined($version)) { +perl comment # could not determine name or version. Error. +perl code my $what; +perl code if (not defined $name) { +perl code $what = 'name'; +perl code $what .= ' and version' if not defined $version; +perl code } +perl code elsif (not defined $version) { +perl code $what = 'version'; +perl code } +perl blank +perl code carp("I was unable to determine the $what of the PAR distribution. Please create a Makefile or META.yml file from which we can infer the information or just specify the missing information as an option to blib_to_par."); +perl code return(); +perl code } +perl blank +perl code $name =~ s/\s+$//; +perl code $version =~ s/\s+$//; +perl blank +perl code my $file = "$name-$version-$suffix"; +perl code unlink $file if -f $file; +perl blank +perl code print META << "YAML" if fileno(META); +perl code name: $name +perl code version: $version +perl code build_requires: {} +perl code conflicts: {} +perl code dist_name: $file +perl code distribution_type: par +perl code dynamic_config: 0 +perl code generated_by: 'PAR::Dist version $PAR::Dist::VERSION' +perl code license: unknown +perl code YAML +perl code close META; +perl blank +perl code mkdir('blib', 0777); +perl code chdir('blib'); +perl code _zip(dist => File::Spec->catfile(File::Spec->updir, $file)) or die $!; +perl code chdir(File::Spec->updir); +perl blank +perl code unlink File::Spec->catfile("blib", "MANIFEST"); +perl code unlink File::Spec->catfile("blib", "META.yml"); +perl blank +perl code $dist ||= File::Spec->catfile($cwd, $file) if $cwd; +perl blank +perl code if ($dist and $file ne $dist) { +perl code rename( $file => $dist ); +perl code $file = $dist; +perl code } +perl blank +perl code my $pathname = File::Spec->rel2abs($file); +perl code if ($^O eq 'MSWin32') { +perl code $pathname =~ s!\\!/!g; +perl code $pathname =~ s!:!|!g; +perl code }; +perl code print << "."; +perl code Successfully created binary distribution '$file'. +perl code Its contents are accessible in compliant browsers as: +perl code jar:file://$pathname!/MANIFEST +perl code . +perl blank +perl code chdir $cwd if $cwd; +perl code return $file; +perl code } +perl blank +perl code sub _build_blib { +perl code if (-e 'Build') { +perl code system($^X, "Build"); +perl code } +perl code elsif (-e 'Makefile') { +perl code system($Config::Config{make}); +perl code } +perl code elsif (-e 'Build.PL') { +perl code system($^X, "Build.PL"); +perl code system($^X, "Build"); +perl code } +perl code elsif (-e 'Makefile.PL') { +perl code system($^X, "Makefile.PL"); +perl code system($Config::Config{make}); +perl code } +perl code } +perl blank +perl comment =head2 install_par +perl blank +perl comment Installs a PAR distribution into the system, using +perl comment C. +perl blank +perl comment Valid parameters are: +perl blank +perl comment =over 2 +perl blank +perl comment =item dist +perl blank +perl comment The .par file to install. The heuristics outlined in the B +perl comment section above apply. +perl blank +perl comment =item prefix +perl blank +perl comment This string will be prepended to all installation paths. +perl comment If it isn't specified, the environment variable +perl comment C is used as a prefix. +perl blank +perl comment =back +perl blank +perl comment Additionally, you can use several parameters to change the default +perl comment installation destinations. You don't usually have to worry about this +perl comment unless you are installing into a user-local directory. +perl comment The following section outlines the parameter names and default settings: +perl blank +perl comment Parameter From To +perl comment inst_lib blib/lib $Config{installsitelib} (*) +perl comment inst_archlib blib/arch $Config{installsitearch} +perl comment inst_script blib/script $Config{installscript} +perl comment inst_bin blib/bin $Config{installbin} +perl comment inst_man1dir blib/man1 $Config{installman1dir} +perl comment inst_man3dir blib/man3 $Config{installman3dir} +perl comment packlist_read $Config{sitearchexp}/auto/$name/.packlist +perl comment packlist_write $Config{installsitearch}/auto/$name/.packlist +perl blank +perl comment The C parameter is used to control where the F<.packlist> +perl comment file is written to. (Necessary for uninstallation.) +perl comment The C parameter specifies a .packlist file to merge in if +perl comment it exists. By setting any of the above installation targets to C, +perl comment you can remove that target altogether. For example, passing +perl comment C undef, inst_man3dir => undef> means that the contained +perl comment manual pages won't be installed. This is not available for the packlists. +perl blank +perl comment Finally, you may specify a C parameter. Its value should be +perl comment a reference to a hash of custom installation targets such as +perl blank +perl comment custom_targets => { 'blib/my_data' => '/some/path/my_data' } +perl blank +perl comment You can use this to install the F<.par> archives contents to arbitrary +perl comment locations. +perl blank +perl comment If only a single parameter is given, it is treated as the C +perl comment parameter. +perl blank +perl comment =cut +perl blank +perl code sub install_par { +perl code my %args = &_args; +perl code _install_or_uninstall(%args, action => 'install'); +perl code } +perl blank +perl comment =head2 uninstall_par +perl blank +perl comment Uninstalls all previously installed contents of a PAR distribution, +perl comment using C. +perl blank +perl comment Takes almost the same parameters as C, but naturally, +perl comment the installation target parameters do not apply. The only exception +perl comment to this is the C parameter which specifies the +perl comment F<.packlist> file to read the list of installed files from. +perl comment It defaults to C<$Config::Config{installsitearch}/auto/$name/.packlist>. +perl blank +perl comment =cut +perl blank +perl code sub uninstall_par { +perl code my %args = &_args; +perl code _install_or_uninstall(%args, action => 'uninstall'); +perl code } +perl blank +perl code sub _install_or_uninstall { +perl code my %args = &_args; +perl code my $name = $args{name}; +perl code my $action = $args{action}; +perl blank +perl code my %ENV_copy = %ENV; +perl code $ENV{PERL_INSTALL_ROOT} = $args{prefix} if defined $args{prefix}; +perl blank +perl code require Cwd; +perl code my $old_dir = Cwd::cwd(); +perl blank +perl code my ($dist, $tmpdir) = _unzip_to_tmpdir( dist => $args{dist}, subdir => 'blib' ); +perl blank +perl code if ( open (META, File::Spec->catfile('blib', 'META.yml')) ) { +perl code while () { +perl code next unless /^name:\s+(.*)/; +perl code $name = $1; +perl code $name =~ s/\s+$//; +perl code last; +perl code } +perl code close META; +perl code } +perl code return if not defined $name or $name eq ''; +perl blank +perl code if (-d 'script') { +perl code require ExtUtils::MY; +perl code foreach my $file (glob("script/*")) { +perl code next unless -T $file; +perl code ExtUtils::MY->fixin($file); +perl code chmod(0555, $file); +perl code } +perl code } +perl blank +perl code $name =~ s{::|-}{/}g; +perl code require ExtUtils::Install; +perl blank +perl code my $rv; +perl code if ($action eq 'install') { +perl code my $target = _installation_target( File::Spec->curdir, $name, \%args ); +perl code my $custom_targets = $args{custom_targets} || {}; +perl code $target->{$_} = $custom_targets->{$_} foreach keys %{$custom_targets}; +perl blank +perl code $rv = ExtUtils::Install::install($target, 1, 0, 0); +perl code } +perl code elsif ($action eq 'uninstall') { +perl code require Config; +perl code $rv = ExtUtils::Install::uninstall( +perl code $args{packlist_read}||"$Config::Config{installsitearch}/auto/$name/.packlist" +perl code ); +perl code } +perl blank +perl code %ENV = %ENV_copy; +perl blank +perl code chdir($old_dir); +perl code File::Path::rmtree([$tmpdir]); +perl code return $rv; +perl code } +perl blank +perl comment # Returns the default installation target as used by +perl comment # ExtUtils::Install::install(). First parameter should be the base +perl comment # directory containing the blib/ we're installing from. +perl comment # Second parameter should be the name of the distribution for the packlist +perl comment # paths. Third parameter may be a hash reference with user defined keys for +perl comment # the target hash. In fact, any contents that do not start with 'inst_' are +perl comment # skipped. +perl code sub _installation_target { +perl code require Config; +perl code my $dir = shift; +perl code my $name = shift; +perl code my $user = shift || {}; +perl blank +perl comment # accepted sources (and user overrides) +perl code my %sources = ( +perl code inst_lib => File::Spec->catdir($dir,"blib","lib"), +perl code inst_archlib => File::Spec->catdir($dir,"blib","arch"), +perl code inst_bin => File::Spec->catdir($dir,'blib','bin'), +perl code inst_script => File::Spec->catdir($dir,'blib','script'), +perl code inst_man1dir => File::Spec->catdir($dir,'blib','man1'), +perl code inst_man3dir => File::Spec->catdir($dir,'blib','man3'), +perl code packlist_read => 'read', +perl code packlist_write => 'write', +perl code ); +perl blank +perl blank +perl comment # default targets +perl code my $target = { +perl code read => $Config::Config{sitearchexp}."/auto/$name/.packlist", +perl code write => $Config::Config{installsitearch}."/auto/$name/.packlist", +perl code $sources{inst_lib} +perl code => (_directory_not_empty($sources{inst_archlib})) +perl code ? $Config::Config{installsitearch} +perl code : $Config::Config{installsitelib}, +perl code $sources{inst_archlib} => $Config::Config{installsitearch}, +perl code $sources{inst_bin} => $Config::Config{installbin} , +perl code $sources{inst_script} => $Config::Config{installscript}, +perl code $sources{inst_man1dir} => $Config::Config{installman1dir}, +perl code $sources{inst_man3dir} => $Config::Config{installman3dir}, +perl code }; +perl blank +perl comment # Included for future support for ${flavour}perl external lib installation +perl comment # if ($Config::Config{flavour_perl}) { +perl comment # my $ext = File::Spec->catdir($dir, 'blib', 'ext'); +perl comment # # from => to +perl comment # $sources{inst_external_lib} = File::Spec->catdir($ext, 'lib'); +perl comment # $sources{inst_external_bin} = File::Spec->catdir($ext, 'bin'); +perl comment # $sources{inst_external_include} = File::Spec->catdir($ext, 'include'); +perl comment # $sources{inst_external_src} = File::Spec->catdir($ext, 'src'); +perl comment # $target->{ $sources{inst_external_lib} } = $Config::Config{flavour_install_lib}; +perl comment # $target->{ $sources{inst_external_bin} } = $Config::Config{flavour_install_bin}; +perl comment # $target->{ $sources{inst_external_include} } = $Config::Config{flavour_install_include}; +perl comment # $target->{ $sources{inst_external_src} } = $Config::Config{flavour_install_src}; +perl comment # } +perl blank +perl comment # insert user overrides +perl code foreach my $key (keys %$user) { +perl code my $value = $user->{$key}; +perl code if (not defined $value and $key ne 'packlist_read' and $key ne 'packlist_write') { +perl comment # undef means "remove" +perl code delete $target->{ $sources{$key} }; +perl code } +perl code elsif (exists $sources{$key}) { +perl comment # overwrite stuff, don't let the user create new entries +perl code $target->{ $sources{$key} } = $value; +perl code } +perl code } +perl blank +perl code return $target; +perl code } +perl blank +perl code sub _directory_not_empty { +perl code require File::Find; +perl code my($dir) = @_; +perl code my $files = 0; +perl code File::Find::find(sub { +perl code return if $_ eq ".exists"; +perl code if (-f) { +perl code $File::Find::prune++; +perl code $files = 1; +perl code } +perl code }, $dir); +perl code return $files; +perl code } +perl blank +perl comment =head2 sign_par +perl blank +perl comment Digitally sign a PAR distribution using C or B, +perl comment via B. +perl blank +perl comment =cut +perl blank +perl code sub sign_par { +perl code my %args = &_args; +perl code _verify_or_sign(%args, action => 'sign'); +perl code } +perl blank +perl comment =head2 verify_par +perl blank +perl comment Verify the digital signature of a PAR distribution using C or +perl comment B, via B. +perl blank +perl comment Returns a boolean value indicating whether verification passed; C<$!> +perl comment is set to the return code of C. +perl blank +perl comment =cut +perl blank +perl code sub verify_par { +perl code my %args = &_args; +perl code $! = _verify_or_sign(%args, action => 'verify'); +perl code return ( $! == Module::Signature::SIGNATURE_OK() ); +perl code } +perl blank +perl comment =head2 merge_par +perl blank +perl comment Merge two or more PAR distributions into one. First argument must +perl comment be the name of the distribution you want to merge all others into. +perl comment Any following arguments will be interpreted as the file names of +perl comment further PAR distributions to merge into the first one. +perl blank +perl comment merge_par('foo.par', 'bar.par', 'baz.par') +perl blank +perl comment This will merge the distributions C, C and C +perl comment into the distribution C. C will be overwritten! +perl comment The original META.yml of C is retained. +perl blank +perl comment =cut +perl blank +perl code sub merge_par { +perl code my $base_par = shift; +perl code my @additional_pars = @_; +perl code require Cwd; +perl code require File::Copy; +perl code require File::Path; +perl code require File::Find; +perl blank +perl comment # parameter checking +perl code if (not defined $base_par) { +perl code croak "First argument to merge_par() must be the .par archive to modify."; +perl code } +perl blank +perl code if (not -f $base_par or not -r _ or not -w _) { +perl code croak "'$base_par' is not a file or you do not have enough permissions to read and modify it."; +perl code } +perl blank +perl code foreach (@additional_pars) { +perl code if (not -f $_ or not -r _) { +perl code croak "'$_' is not a file or you do not have enough permissions to read it."; +perl code } +perl code } +perl blank +perl comment # The unzipping will change directories. Remember old dir. +perl code my $old_cwd = Cwd::cwd(); +perl blank +perl comment # Unzip the base par to a temp. dir. +perl code (undef, my $base_dir) = _unzip_to_tmpdir( +perl code dist => $base_par, subdir => 'blib' +perl code ); +perl code my $blibdir = File::Spec->catdir($base_dir, 'blib'); +perl blank +perl comment # move the META.yml to the (main) temp. dir. +perl code File::Copy::move( +perl code File::Spec->catfile($blibdir, 'META.yml'), +perl code File::Spec->catfile($base_dir, 'META.yml') +perl code ); +perl comment # delete (incorrect) MANIFEST +perl code unlink File::Spec->catfile($blibdir, 'MANIFEST'); +perl blank +perl comment # extract additional pars and merge +perl code foreach my $par (@additional_pars) { +perl comment # restore original directory because the par path +perl comment # might have been relative! +perl code chdir($old_cwd); +perl code (undef, my $add_dir) = _unzip_to_tmpdir( +perl code dist => $par +perl code ); +perl code my @files; +perl code my @dirs; +perl comment # I hate File::Find +perl comment # And I hate writing portable code, too. +perl code File::Find::find( +perl code {wanted =>sub { +perl code my $file = $File::Find::name; +perl code push @files, $file if -f $file; +perl code push @dirs, $file if -d _; +perl code }}, +perl code $add_dir +perl code ); +perl code my ($vol, $subdir, undef) = File::Spec->splitpath( $add_dir, 1); +perl code my @dir = File::Spec->splitdir( $subdir ); +perl blank +perl comment # merge directory structure +perl code foreach my $dir (@dirs) { +perl code my ($v, $d, undef) = File::Spec->splitpath( $dir, 1 ); +perl code my @d = File::Spec->splitdir( $d ); +perl code shift @d foreach @dir; # remove tmp dir from path +perl code my $target = File::Spec->catdir( $blibdir, @d ); +perl code mkdir($target); +perl code } +perl blank +perl comment # merge files +perl code foreach my $file (@files) { +perl code my ($v, $d, $f) = File::Spec->splitpath( $file ); +perl code my @d = File::Spec->splitdir( $d ); +perl code shift @d foreach @dir; # remove tmp dir from path +perl code my $target = File::Spec->catfile( +perl code File::Spec->catdir( $blibdir, @d ), +perl code $f +perl code ); +perl code File::Copy::copy($file, $target) +perl code or die "Could not copy '$file' to '$target': $!"; +perl blank +perl code } +perl code chdir($old_cwd); +perl code File::Path::rmtree([$add_dir]); +perl code } +perl blank +perl comment # delete (copied) MANIFEST and META.yml +perl code unlink File::Spec->catfile($blibdir, 'MANIFEST'); +perl code unlink File::Spec->catfile($blibdir, 'META.yml'); +perl blank +perl code chdir($base_dir); +perl code my $resulting_par_file = Cwd::abs_path(blib_to_par()); +perl code chdir($old_cwd); +perl code File::Copy::move($resulting_par_file, $base_par); +perl blank +perl code File::Path::rmtree([$base_dir]); +perl code } +perl blank +perl blank +perl comment =head2 remove_man +perl blank +perl comment Remove the man pages from a PAR distribution. Takes one named +perl comment parameter: I which should be the name (and path) of the +perl comment PAR distribution file. The calling conventions outlined in +perl comment the C section above apply. +perl blank +perl comment The PAR archive will be +perl comment extracted, stripped of all C and C subdirectories +perl comment and then repackaged into the original file. +perl blank +perl comment =cut +perl blank +perl code sub remove_man { +perl code my %args = &_args; +perl code my $par = $args{dist}; +perl code require Cwd; +perl code require File::Copy; +perl code require File::Path; +perl code require File::Find; +perl blank +perl comment # parameter checking +perl code if (not defined $par) { +perl code croak "First argument to remove_man() must be the .par archive to modify."; +perl code } +perl blank +perl code if (not -f $par or not -r _ or not -w _) { +perl code croak "'$par' is not a file or you do not have enough permissions to read and modify it."; +perl code } +perl blank +perl comment # The unzipping will change directories. Remember old dir. +perl code my $old_cwd = Cwd::cwd(); +perl blank +perl comment # Unzip the base par to a temp. dir. +perl code (undef, my $base_dir) = _unzip_to_tmpdir( +perl code dist => $par, subdir => 'blib' +perl code ); +perl code my $blibdir = File::Spec->catdir($base_dir, 'blib'); +perl blank +perl comment # move the META.yml to the (main) temp. dir. +perl code File::Copy::move( +perl code File::Spec->catfile($blibdir, 'META.yml'), +perl code File::Spec->catfile($base_dir, 'META.yml') +perl code ); +perl comment # delete (incorrect) MANIFEST +perl code unlink File::Spec->catfile($blibdir, 'MANIFEST'); +perl blank +perl code opendir DIRECTORY, 'blib' or die $!; +perl code my @dirs = grep { /^blib\/(?:man\d*|html)$/ } +perl code grep { -d $_ } +perl code map { File::Spec->catfile('blib', $_) } +perl code readdir DIRECTORY; +perl code close DIRECTORY; +perl blank +perl code File::Path::rmtree(\@dirs); +perl blank +perl code chdir($base_dir); +perl code my $resulting_par_file = Cwd::abs_path(blib_to_par()); +perl code chdir($old_cwd); +perl code File::Copy::move($resulting_par_file, $par); +perl blank +perl code File::Path::rmtree([$base_dir]); +perl code } +perl blank +perl blank +perl comment =head2 get_meta +perl blank +perl comment Opens a PAR archive and extracts the contained META.yml file. +perl comment Returns the META.yml file as a string. +perl blank +perl comment Takes one named parameter: I. If only one parameter is +perl comment passed, it is treated as the I parameter. (Have a look +perl comment at the description in the C section above.) +perl blank +perl comment Returns undef if no PAR archive or no META.yml within the +perl comment archive were found. +perl blank +perl comment =cut +perl blank +perl code sub get_meta { +perl code my %args = &_args; +perl code my $dist = $args{dist}; +perl code return undef if not defined $dist or not -r $dist; +perl code require Cwd; +perl code require File::Path; +perl blank +perl comment # The unzipping will change directories. Remember old dir. +perl code my $old_cwd = Cwd::cwd(); +perl blank +perl comment # Unzip the base par to a temp. dir. +perl code (undef, my $base_dir) = _unzip_to_tmpdir( +perl code dist => $dist, subdir => 'blib' +perl code ); +perl code my $blibdir = File::Spec->catdir($base_dir, 'blib'); +perl blank +perl code my $meta = File::Spec->catfile($blibdir, 'META.yml'); +perl blank +perl code if (not -r $meta) { +perl code return undef; +perl code } +perl blank +perl code open FH, '<', $meta +perl code or die "Could not open file '$meta' for reading: $!"; +perl blank +perl code local $/ = undef; +perl code my $meta_text = ; +perl code close FH; +perl blank +perl code chdir($old_cwd); +perl blank +perl code File::Path::rmtree([$base_dir]); +perl blank +perl code return $meta_text; +perl code } +perl blank +perl blank +perl blank +perl code sub _unzip { +perl code my %args = &_args; +perl code my $dist = $args{dist}; +perl code my $path = $args{path} || File::Spec->curdir; +perl code return unless -f $dist; +perl blank +perl comment # Try fast unzipping first +perl code if (eval { require Archive::Unzip::Burst; 1 }) { +perl code my $return = Archive::Unzip::Burst::unzip($dist, $path); +perl code return if $return; # true return value == error (a la system call) +perl code } +perl comment # Then slow unzipping +perl code if (eval { require Archive::Zip; 1 }) { +perl code my $zip = Archive::Zip->new; +perl code local %SIG; +perl code $SIG{__WARN__} = sub { print STDERR $_[0] unless $_[0] =~ /\bstat\b/ }; +perl code return unless $zip->read($dist) == Archive::Zip::AZ_OK() +perl code and $zip->extractTree('', "$path/") == Archive::Zip::AZ_OK(); +perl code } +perl comment # Then fall back to the system +perl code else { +perl code return if system(unzip => $dist, '-d', $path); +perl code } +perl blank +perl code return 1; +perl code } +perl blank +perl code sub _zip { +perl code my %args = &_args; +perl code my $dist = $args{dist}; +perl blank +perl code if (eval { require Archive::Zip; 1 }) { +perl code my $zip = Archive::Zip->new; +perl code $zip->addTree( File::Spec->curdir, '' ); +perl code $zip->writeToFileNamed( $dist ) == Archive::Zip::AZ_OK() or die $!; +perl code } +perl code else { +perl code system(qw(zip -r), $dist, File::Spec->curdir) and die $!; +perl code } +perl code } +perl blank +perl blank +perl comment # This sub munges the arguments to most of the PAR::Dist functions +perl comment # into a hash. On the way, it downloads PAR archives as necessary, etc. +perl code sub _args { +perl comment # default to the first .par in the CWD +perl code if (not @_) { +perl code @_ = (glob('*.par'))[0]; +perl code } +perl blank +perl comment # single argument => it's a distribution file name or URL +perl code @_ = (dist => @_) if @_ == 1; +perl blank +perl code my %args = @_; +perl code $args{name} ||= $args{dist}; +perl blank +perl comment # If we are installing from an URL, we want to munge the +perl comment # distribution name so that it is in form "Module-Name" +perl code if (defined $args{name}) { +perl code $args{name} =~ s/^\w+:\/\///; +perl code my @elems = parse_dist_name($args{name}); +perl comment # @elems is name, version, arch, perlversion +perl code if (defined $elems[0]) { +perl code $args{name} = $elems[0]; +perl code } +perl code else { +perl code $args{name} =~ s/^.*\/([^\/]+)$/$1/; +perl code $args{name} =~ s/^([0-9A-Za-z_-]+)-\d+\..+$/$1/; +perl code } +perl code } +perl blank +perl comment # append suffix if there is none +perl code if ($args{dist} and not $args{dist} =~ /\.[a-zA-Z_][^.]*$/) { +perl code require Config; +perl code my $suffix = $args{suffix}; +perl code $suffix ||= "$Config::Config{archname}-$Config::Config{version}.par"; +perl code $args{dist} .= "-$suffix"; +perl code } +perl blank +perl comment # download if it's an URL +perl code if ($args{dist} and $args{dist} =~ m!^\w+://!) { +perl code $args{dist} = _fetch(dist => $args{dist}) +perl code } +perl blank +perl code return %args; +perl code } +perl blank +perl blank +perl comment # Download PAR archive, but only if necessary (mirror!) +perl code my %escapes; +perl code sub _fetch { +perl code my %args = @_; +perl blank +perl code if ($args{dist} =~ s/^file:\/\///) { +perl code return $args{dist} if -e $args{dist}; +perl code return; +perl code } +perl code require LWP::Simple; +perl blank +perl code $ENV{PAR_TEMP} ||= File::Spec->catdir(File::Spec->tmpdir, 'par'); +perl code mkdir $ENV{PAR_TEMP}, 0777; +perl code %escapes = map { chr($_) => sprintf("%%%02X", $_) } 0..255 unless %escapes; +perl blank +perl code $args{dist} =~ s{^cpan://((([a-zA-Z])[a-zA-Z])[-_a-zA-Z]+)/} +perl code {http://www.cpan.org/modules/by-authors/id/\U$3/$2/$1\E/}; +perl blank +perl code my $file = $args{dist}; +perl code $file =~ s/([^\w\.])/$escapes{$1}/g; +perl code $file = File::Spec->catfile( $ENV{PAR_TEMP}, $file); +perl code my $rc = LWP::Simple::mirror( $args{dist}, $file ); +perl blank +perl code if (!LWP::Simple::is_success($rc) and $rc != 304) { +perl code die "Error $rc: ", LWP::Simple::status_message($rc), " ($args{dist})\n"; +perl code } +perl blank +perl code return $file if -e $file; +perl code return; +perl code } +perl blank +perl code sub _verify_or_sign { +perl code my %args = &_args; +perl blank +perl code require File::Path; +perl code require Module::Signature; +perl code die "Module::Signature version 0.25 required" +perl code unless Module::Signature->VERSION >= 0.25; +perl blank +perl code require Cwd; +perl code my $cwd = Cwd::cwd(); +perl code my $action = $args{action}; +perl code my ($dist, $tmpdir) = _unzip_to_tmpdir($args{dist}); +perl code $action ||= (-e 'SIGNATURE' ? 'verify' : 'sign'); +perl blank +perl code if ($action eq 'sign') { +perl code open FH, '>SIGNATURE' unless -e 'SIGNATURE'; +perl code open FH, 'MANIFEST' or die $!; +perl blank +perl code local $/; +perl code my $out = ; +perl code if ($out !~ /^SIGNATURE(?:\s|$)/m) { +perl code $out =~ s/^(?!\s)/SIGNATURE\n/m; +perl code open FH, '>MANIFEST' or die $!; +perl code print FH $out; +perl code } +perl code close FH; +perl blank +perl code $args{overwrite} = 1 unless exists $args{overwrite}; +perl code $args{skip} = 0 unless exists $args{skip}; +perl code } +perl blank +perl code my $rv = Module::Signature->can($action)->(%args); +perl code _zip(dist => $dist) if $action eq 'sign'; +perl code File::Path::rmtree([$tmpdir]); +perl blank +perl code chdir($cwd); +perl code return $rv; +perl code } +perl blank +perl code sub _unzip_to_tmpdir { +perl code my %args = &_args; +perl blank +perl code require File::Temp; +perl blank +perl code my $dist = File::Spec->rel2abs($args{dist}); +perl code my $tmpdirname = File::Spec->catdir(File::Spec->tmpdir, "parXXXXX"); +perl code my $tmpdir = File::Temp::mkdtemp($tmpdirname) +perl code or die "Could not create temporary directory from template '$tmpdirname': $!"; +perl code my $path = $tmpdir; +perl code $path = File::Spec->catdir($tmpdir, $args{subdir}) if defined $args{subdir}; +perl code _unzip(dist => $dist, path => $path); +perl blank +perl code chdir $tmpdir; +perl code return ($dist, $tmpdir); +perl code } +perl blank +perl blank +perl blank +perl comment =head2 parse_dist_name +perl blank +perl comment First argument must be a distribution file name. The file name +perl comment is parsed into I, I, +perl comment I, and I. +perl blank +perl comment Returns the results as a list in the above order. +perl comment If any or all of the above cannot be determined, returns undef instead +perl comment of the undetermined elements. +perl blank +perl comment Supported formats are: +perl blank +perl comment Math-Symbolic-0.502-x86_64-linux-gnu-thread-multi-5.8.7 +perl blank +perl comment Math-Symbolic-0.502 +perl blank +perl comment The ".tar.gz" or ".par" extensions as well as any +perl comment preceding paths are stripped before parsing. Starting with C +perl comment 0.22, versions containing a preceding C are parsed correctly. +perl blank +perl comment This function is not exported by default. +perl blank +perl comment =cut +perl blank +perl code sub parse_dist_name { +perl code my $file = shift; +perl code return(undef, undef, undef, undef) if not defined $file; +perl blank +perl code (undef, undef, $file) = File::Spec->splitpath($file); +perl blank +perl code my $version = qr/v?(?:\d+(?:_\d+)?|\d*(?:\.\d+(?:_\d+)?)+)/; +perl code $file =~ s/\.(?:par|tar\.gz|tar)$//i; +perl code my @elem = split /-/, $file; +perl code my (@dn, $dv, @arch, $pv); +perl code while (@elem) { +perl code my $e = shift @elem; +perl code if ( +perl code $e =~ /^$version$/o +perl code and not(# if not next token also a version +perl comment # (assumes an arch string doesnt start with a version...) +perl code @elem and $elem[0] =~ /^$version$/o +perl code ) +perl code ) { +perl blank +perl code $dv = $e; +perl code last; +perl code } +perl code push @dn, $e; +perl code } +perl blank +perl code my $dn; +perl code $dn = join('-', @dn) if @dn; +perl blank +perl code if (not @elem) { +perl code return( $dn, $dv, undef, undef); +perl code } +perl blank +perl code while (@elem) { +perl code my $e = shift @elem; +perl code if ($e =~ /^$version|any_version$/) { +perl code $pv = $e; +perl code last; +perl code } +perl code push @arch, $e; +perl code } +perl blank +perl code my $arch; +perl code $arch = join('-', @arch) if @arch; +perl blank +perl code return($dn, $dv, $arch, $pv); +perl code } +perl blank +perl comment =head2 generate_blib_stub +perl blank +perl comment Creates a F subdirectory in the current directory +perl comment and prepares a F with meta information for a +perl comment new PAR distribution. First argument should be the name of the +perl comment PAR distribution in a format understood by C. +perl comment Alternatively, named arguments resembling those of +perl comment C are accepted. +perl blank +perl comment After running C and injecting files into +perl comment the F directory, you can create a PAR distribution +perl comment using C. +perl comment This function is useful for creating custom PAR distributions +perl comment from scratch. (I.e. not from an unpacked CPAN distribution) +perl comment Example: +perl blank +perl comment use PAR::Dist; +perl comment use File::Copy 'copy'; +perl blank +perl comment generate_blib_stub( +perl comment name => 'MyApp', version => '1.00' +perl comment ); +perl comment copy('MyApp.pm', 'blib/lib/MyApp.pm'); +perl comment blib_to_par(); # generates the .par file! +perl blank +perl comment C will not overwrite existing files. +perl blank +perl comment =cut +perl blank +perl code sub generate_blib_stub { +perl code my %args = &_args; +perl code my $dist = $args{dist}; +perl code require Config; +perl blank +perl code my $name = $args{name}; +perl code my $version = $args{version}; +perl code my $suffix = $args{suffix}; +perl blank +perl code my ($parse_name, $parse_version, $archname, $perlversion) +perl code = parse_dist_name($dist); +perl blank +perl code $name ||= $parse_name; +perl code $version ||= $parse_version; +perl code $suffix = "$archname-$perlversion" +perl code if (not defined $suffix or $suffix eq '') +perl code and $archname and $perlversion; +perl blank +perl code $suffix ||= "$Config::Config{archname}-$Config::Config{version}"; +perl code if ( grep { not defined $_ } ($name, $version, $suffix) ) { +perl code warn "Could not determine distribution meta information from distribution name '$dist'"; +perl code return(); +perl code } +perl code $suffix =~ s/\.par$//; +perl blank +perl code if (not -f 'META.yml') { +perl code open META, '>', 'META.yml' +perl code or die "Could not open META.yml file for writing: $!"; +perl code print META << "YAML" if fileno(META); +perl code name: $name +perl code version: $version +perl code build_requires: {} +perl code conflicts: {} +perl code dist_name: $name-$version-$suffix.par +perl code distribution_type: par +perl code dynamic_config: 0 +perl code generated_by: 'PAR::Dist version $PAR::Dist::VERSION' +perl code license: unknown +perl code YAML +perl code close META; +perl code } +perl blank +perl code mkdir('blib'); +perl code mkdir(File::Spec->catdir('blib', 'lib')); +perl code mkdir(File::Spec->catdir('blib', 'script')); +perl blank +perl code return 1; +perl code } +perl blank +perl blank +perl comment =head2 contains_binaries +perl blank +perl comment This function is not exported by default. +perl blank +perl comment Opens a PAR archive tries to determine whether that archive +perl comment contains platform-specific binary code. +perl blank +perl comment Takes one named parameter: I. If only one parameter is +perl comment passed, it is treated as the I parameter. (Have a look +perl comment at the description in the C section above.) +perl blank +perl comment Throws a fatal error if the PAR archive could not be found. +perl blank +perl comment Returns one if the PAR was found to contain binary code +perl comment and zero otherwise. +perl blank +perl comment =cut +perl blank +perl code sub contains_binaries { +perl code require File::Find; +perl code my %args = &_args; +perl code my $dist = $args{dist}; +perl code return undef if not defined $dist or not -r $dist; +perl code require Cwd; +perl code require File::Path; +perl blank +perl comment # The unzipping will change directories. Remember old dir. +perl code my $old_cwd = Cwd::cwd(); +perl blank +perl comment # Unzip the base par to a temp. dir. +perl code (undef, my $base_dir) = _unzip_to_tmpdir( +perl code dist => $dist, subdir => 'blib' +perl code ); +perl code my $blibdir = File::Spec->catdir($base_dir, 'blib'); +perl code my $archdir = File::Spec->catdir($blibdir, 'arch'); +perl blank +perl code my $found = 0; +perl blank +perl code File::Find::find( +perl code sub { +perl code $found++ if -f $_ and not /^\.exists$/; +perl code }, +perl code $archdir +perl code ); +perl blank +perl code chdir($old_cwd); +perl blank +perl code File::Path::rmtree([$base_dir]); +perl blank +perl code return $found ? 1 : 0; +perl code } +perl blank +perl code 1; +perl blank +perl comment =head1 SEE ALSO +perl blank +perl comment L, L, L, L +perl blank +perl comment =head1 AUTHORS +perl blank +perl comment Audrey Tang Ecpan@audreyt.orgE 2003-2007 +perl blank +perl comment Steffen Mueller Esmueller@cpan.orgE 2005-2007 +perl blank +perl comment PAR has a mailing list, Epar@perl.orgE, that you can write to; +perl comment send an empty mail to Epar-subscribe@perl.orgE to join the list +perl comment and participate in the discussion. +perl blank +perl comment Please send bug reports to Ebug-par@rt.cpan.orgE. +perl blank +perl comment =head1 COPYRIGHT +perl blank +perl comment Copyright 2003-2007 by Audrey Tang Eautrijus@autrijus.orgE. +perl blank +perl comment This program is free software; you can redistribute it and/or modify it +perl comment under the same terms as Perl itself. +perl blank +perl comment See L +perl blank +perl comment =cut diff --git a/test/expected_dir/perl_module.pm/perl/blanks b/test/expected_dir/perl_module.pm/perl/blanks deleted file mode 100644 index 44dfb1d..0000000 --- a/test/expected_dir/perl_module.pm/perl/blanks +++ /dev/null @@ -1 +0,0 @@ -264 \ No newline at end of file diff --git a/test/expected_dir/perl_module.pm/perl/code b/test/expected_dir/perl_module.pm/perl/code deleted file mode 100644 index 48eac67..0000000 --- a/test/expected_dir/perl_module.pm/perl/code +++ /dev/null @@ -1,642 +0,0 @@ -package PAR::Dist; -require Exporter; -use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK/; -$VERSION = '0.29'; -@ISA = 'Exporter'; -@EXPORT = qw/ -blib_to_par -install_par -uninstall_par -sign_par -verify_par -merge_par -remove_man -get_meta -generate_blib_stub -/; -@EXPORT_OK = qw/ -parse_dist_name -contains_binaries -/; -use strict; -use Carp qw/carp croak/; -use File::Spec; -sub blib_to_par { -@_ = (path => @_) if @_ == 1; -my %args = @_; -require Config; -my $dist; -my $path = $args{path}; -$dist = File::Spec->rel2abs($args{dist}) if $args{dist}; -my $name = $args{name}; -my $version = $args{version}; -my $suffix = $args{suffix} || "$Config::Config{archname}-$Config::Config{version}.par"; -my $cwd; -if (defined $path) { -require Cwd; -$cwd = Cwd::cwd(); -chdir $path; -} -_build_blib() unless -d "blib"; -my @files; -open MANIFEST, ">", File::Spec->catfile("blib", "MANIFEST") or die $!; -open META, ">", File::Spec->catfile("blib", "META.yml") or die $!; -require File::Find; -File::Find::find( sub { -next unless $File::Find::name; -(-r && !-d) and push ( @files, substr($File::Find::name, 5) ); -} , 'blib' ); -print MANIFEST join( -"\n", -' ', -(sort @files), -q( # ) -); -close MANIFEST; -if (open(OLD_META, "META.yml")) { -while () { -if (/^distribution_type:/) { -print META "distribution_type: par\n"; -} -else { -print META $_; -} -if (/^name:\s+(.*)/) { -$name ||= $1; -$name =~ s/::/-/g; -} -elsif (/^version:\s+.*Module::Build::Version/) { -while () { -/^\s+original:\s+(.*)/ or next; -$version ||= $1; -last; -} -} -elsif (/^version:\s+(.*)/) { -$version ||= $1; -} -} -close OLD_META; -close META; -} -if ((!$name or !$version) and open(MAKEFILE, "Makefile")) { -while () { -if (/^DISTNAME\s+=\s+(.*)$/) { -$name ||= $1; -} -elsif (/^VERSION\s+=\s+(.*)$/) { -$version ||= $1; -} -} -} -if (not defined($name) or not defined($version)) { -my $what; -if (not defined $name) { -$what = 'name'; -$what .= ' and version' if not defined $version; -} -elsif (not defined $version) { -$what = 'version'; -} -carp("I was unable to determine the $what of the PAR distribution. Please create a Makefile or META.yml file from which we can infer the information or just specify the missing information as an option to blib_to_par."); -return(); -} -$name =~ s/\s+$//; -$version =~ s/\s+$//; -my $file = "$name-$version-$suffix"; -unlink $file if -f $file; -print META << "YAML" if fileno(META); -name: $name -version: $version -build_requires: {} -conflicts: {} -dist_name: $file -distribution_type: par -dynamic_config: 0 -generated_by: 'PAR::Dist version $PAR::Dist::VERSION' -license: unknown -YAML -close META; -mkdir('blib', 0777); -chdir('blib'); -_zip(dist => File::Spec->catfile(File::Spec->updir, $file)) or die $!; -chdir(File::Spec->updir); -unlink File::Spec->catfile("blib", "MANIFEST"); -unlink File::Spec->catfile("blib", "META.yml"); -$dist ||= File::Spec->catfile($cwd, $file) if $cwd; -if ($dist and $file ne $dist) { -rename( $file => $dist ); -$file = $dist; -} -my $pathname = File::Spec->rel2abs($file); -if ($^O eq 'MSWin32') { -$pathname =~ s!\\!/!g; -$pathname =~ s!:!|!g; -}; -print << "."; -Successfully created binary distribution '$file'. -Its contents are accessible in compliant browsers as: -jar:file://$pathname!/MANIFEST -. -chdir $cwd if $cwd; -return $file; -} -sub _build_blib { -if (-e 'Build') { -system($^X, "Build"); -} -elsif (-e 'Makefile') { -system($Config::Config{make}); -} -elsif (-e 'Build.PL') { -system($^X, "Build.PL"); -system($^X, "Build"); -} -elsif (-e 'Makefile.PL') { -system($^X, "Makefile.PL"); -system($Config::Config{make}); -} -} -sub install_par { -my %args = &_args; -_install_or_uninstall(%args, action => 'install'); -} -sub uninstall_par { -my %args = &_args; -_install_or_uninstall(%args, action => 'uninstall'); -} -sub _install_or_uninstall { -my %args = &_args; -my $name = $args{name}; -my $action = $args{action}; -my %ENV_copy = %ENV; -$ENV{PERL_INSTALL_ROOT} = $args{prefix} if defined $args{prefix}; -require Cwd; -my $old_dir = Cwd::cwd(); -my ($dist, $tmpdir) = _unzip_to_tmpdir( dist => $args{dist}, subdir => 'blib' ); -if ( open (META, File::Spec->catfile('blib', 'META.yml')) ) { -while () { -next unless /^name:\s+(.*)/; -$name = $1; -$name =~ s/\s+$//; -last; -} -close META; -} -return if not defined $name or $name eq ''; -if (-d 'script') { -require ExtUtils::MY; -foreach my $file (glob("script/*")) { -next unless -T $file; -ExtUtils::MY->fixin($file); -chmod(0555, $file); -} -} -$name =~ s{::|-}{/}g; -require ExtUtils::Install; -my $rv; -if ($action eq 'install') { -my $target = _installation_target( File::Spec->curdir, $name, \%args ); -my $custom_targets = $args{custom_targets} || {}; -$target->{$_} = $custom_targets->{$_} foreach keys %{$custom_targets}; -$rv = ExtUtils::Install::install($target, 1, 0, 0); -} -elsif ($action eq 'uninstall') { -require Config; -$rv = ExtUtils::Install::uninstall( -$args{packlist_read}||"$Config::Config{installsitearch}/auto/$name/.packlist" -); -} -%ENV = %ENV_copy; -chdir($old_dir); -File::Path::rmtree([$tmpdir]); -return $rv; -} -sub _installation_target { -require Config; -my $dir = shift; -my $name = shift; -my $user = shift || {}; -my %sources = ( -inst_lib => File::Spec->catdir($dir,"blib","lib"), -inst_archlib => File::Spec->catdir($dir,"blib","arch"), -inst_bin => File::Spec->catdir($dir,'blib','bin'), -inst_script => File::Spec->catdir($dir,'blib','script'), -inst_man1dir => File::Spec->catdir($dir,'blib','man1'), -inst_man3dir => File::Spec->catdir($dir,'blib','man3'), -packlist_read => 'read', -packlist_write => 'write', -); -my $target = { -read => $Config::Config{sitearchexp}."/auto/$name/.packlist", -write => $Config::Config{installsitearch}."/auto/$name/.packlist", -$sources{inst_lib} -=> (_directory_not_empty($sources{inst_archlib})) -? $Config::Config{installsitearch} -: $Config::Config{installsitelib}, -$sources{inst_archlib} => $Config::Config{installsitearch}, -$sources{inst_bin} => $Config::Config{installbin} , -$sources{inst_script} => $Config::Config{installscript}, -$sources{inst_man1dir} => $Config::Config{installman1dir}, -$sources{inst_man3dir} => $Config::Config{installman3dir}, -}; -foreach my $key (keys %$user) { -my $value = $user->{$key}; -if (not defined $value and $key ne 'packlist_read' and $key ne 'packlist_write') { -delete $target->{ $sources{$key} }; -} -elsif (exists $sources{$key}) { -$target->{ $sources{$key} } = $value; -} -} -return $target; -} -sub _directory_not_empty { -require File::Find; -my($dir) = @_; -my $files = 0; -File::Find::find(sub { -return if $_ eq ".exists"; -if (-f) { -$File::Find::prune++; -$files = 1; -} -}, $dir); -return $files; -} -sub sign_par { -my %args = &_args; -_verify_or_sign(%args, action => 'sign'); -} -sub verify_par { -my %args = &_args; -$! = _verify_or_sign(%args, action => 'verify'); -return ( $! == Module::Signature::SIGNATURE_OK() ); -} -sub merge_par { -my $base_par = shift; -my @additional_pars = @_; -require Cwd; -require File::Copy; -require File::Path; -require File::Find; -if (not defined $base_par) { -croak "First argument to merge_par() must be the .par archive to modify."; -} -if (not -f $base_par or not -r _ or not -w _) { -croak "'$base_par' is not a file or you do not have enough permissions to read and modify it."; -} -foreach (@additional_pars) { -if (not -f $_ or not -r _) { -croak "'$_' is not a file or you do not have enough permissions to read it."; -} -} -my $old_cwd = Cwd::cwd(); -(undef, my $base_dir) = _unzip_to_tmpdir( -dist => $base_par, subdir => 'blib' -); -my $blibdir = File::Spec->catdir($base_dir, 'blib'); -File::Copy::move( -File::Spec->catfile($blibdir, 'META.yml'), -File::Spec->catfile($base_dir, 'META.yml') -); -unlink File::Spec->catfile($blibdir, 'MANIFEST'); -foreach my $par (@additional_pars) { -chdir($old_cwd); -(undef, my $add_dir) = _unzip_to_tmpdir( -dist => $par -); -my @files; -my @dirs; -File::Find::find( -{wanted =>sub { -my $file = $File::Find::name; -push @files, $file if -f $file; -push @dirs, $file if -d _; -}}, -$add_dir -); -my ($vol, $subdir, undef) = File::Spec->splitpath( $add_dir, 1); -my @dir = File::Spec->splitdir( $subdir ); -foreach my $dir (@dirs) { -my ($v, $d, undef) = File::Spec->splitpath( $dir, 1 ); -my @d = File::Spec->splitdir( $d ); -shift @d foreach @dir; # remove tmp dir from path -my $target = File::Spec->catdir( $blibdir, @d ); -mkdir($target); -} -foreach my $file (@files) { -my ($v, $d, $f) = File::Spec->splitpath( $file ); -my @d = File::Spec->splitdir( $d ); -shift @d foreach @dir; # remove tmp dir from path -my $target = File::Spec->catfile( -File::Spec->catdir( $blibdir, @d ), -$f -); -File::Copy::copy($file, $target) -or die "Could not copy '$file' to '$target': $!"; -} -chdir($old_cwd); -File::Path::rmtree([$add_dir]); -} -unlink File::Spec->catfile($blibdir, 'MANIFEST'); -unlink File::Spec->catfile($blibdir, 'META.yml'); -chdir($base_dir); -my $resulting_par_file = Cwd::abs_path(blib_to_par()); -chdir($old_cwd); -File::Copy::move($resulting_par_file, $base_par); -File::Path::rmtree([$base_dir]); -} -sub remove_man { -my %args = &_args; -my $par = $args{dist}; -require Cwd; -require File::Copy; -require File::Path; -require File::Find; -if (not defined $par) { -croak "First argument to remove_man() must be the .par archive to modify."; -} -if (not -f $par or not -r _ or not -w _) { -croak "'$par' is not a file or you do not have enough permissions to read and modify it."; -} -my $old_cwd = Cwd::cwd(); -(undef, my $base_dir) = _unzip_to_tmpdir( -dist => $par, subdir => 'blib' -); -my $blibdir = File::Spec->catdir($base_dir, 'blib'); -File::Copy::move( -File::Spec->catfile($blibdir, 'META.yml'), -File::Spec->catfile($base_dir, 'META.yml') -); -unlink File::Spec->catfile($blibdir, 'MANIFEST'); -opendir DIRECTORY, 'blib' or die $!; -my @dirs = grep { /^blib\/(?:man\d*|html)$/ } -grep { -d $_ } -map { File::Spec->catfile('blib', $_) } -readdir DIRECTORY; -close DIRECTORY; -File::Path::rmtree(\@dirs); -chdir($base_dir); -my $resulting_par_file = Cwd::abs_path(blib_to_par()); -chdir($old_cwd); -File::Copy::move($resulting_par_file, $par); -File::Path::rmtree([$base_dir]); -} -sub get_meta { -my %args = &_args; -my $dist = $args{dist}; -return undef if not defined $dist or not -r $dist; -require Cwd; -require File::Path; -my $old_cwd = Cwd::cwd(); -(undef, my $base_dir) = _unzip_to_tmpdir( -dist => $dist, subdir => 'blib' -); -my $blibdir = File::Spec->catdir($base_dir, 'blib'); -my $meta = File::Spec->catfile($blibdir, 'META.yml'); -if (not -r $meta) { -return undef; -} -open FH, '<', $meta -or die "Could not open file '$meta' for reading: $!"; -local $/ = undef; -my $meta_text = ; -close FH; -chdir($old_cwd); -File::Path::rmtree([$base_dir]); -return $meta_text; -} -sub _unzip { -my %args = &_args; -my $dist = $args{dist}; -my $path = $args{path} || File::Spec->curdir; -return unless -f $dist; -if (eval { require Archive::Unzip::Burst; 1 }) { -my $return = Archive::Unzip::Burst::unzip($dist, $path); -return if $return; # true return value == error (a la system call) -} -if (eval { require Archive::Zip; 1 }) { -my $zip = Archive::Zip->new; -local %SIG; -$SIG{__WARN__} = sub { print STDERR $_[0] unless $_[0] =~ /\bstat\b/ }; -return unless $zip->read($dist) == Archive::Zip::AZ_OK() -and $zip->extractTree('', "$path/") == Archive::Zip::AZ_OK(); -} -else { -return if system(unzip => $dist, '-d', $path); -} -return 1; -} -sub _zip { -my %args = &_args; -my $dist = $args{dist}; -if (eval { require Archive::Zip; 1 }) { -my $zip = Archive::Zip->new; -$zip->addTree( File::Spec->curdir, '' ); -$zip->writeToFileNamed( $dist ) == Archive::Zip::AZ_OK() or die $!; -} -else { -system(qw(zip -r), $dist, File::Spec->curdir) and die $!; -} -} -sub _args { -if (not @_) { -@_ = (glob('*.par'))[0]; -} -@_ = (dist => @_) if @_ == 1; -my %args = @_; -$args{name} ||= $args{dist}; -if (defined $args{name}) { -$args{name} =~ s/^\w+:\/\///; -my @elems = parse_dist_name($args{name}); -if (defined $elems[0]) { -$args{name} = $elems[0]; -} -else { -$args{name} =~ s/^.*\/([^\/]+)$/$1/; -$args{name} =~ s/^([0-9A-Za-z_-]+)-\d+\..+$/$1/; -} -} -if ($args{dist} and not $args{dist} =~ /\.[a-zA-Z_][^.]*$/) { -require Config; -my $suffix = $args{suffix}; -$suffix ||= "$Config::Config{archname}-$Config::Config{version}.par"; -$args{dist} .= "-$suffix"; -} -if ($args{dist} and $args{dist} =~ m!^\w+://!) { -$args{dist} = _fetch(dist => $args{dist}) -} -return %args; -} -my %escapes; -sub _fetch { -my %args = @_; -if ($args{dist} =~ s/^file:\/\///) { -return $args{dist} if -e $args{dist}; -return; -} -require LWP::Simple; -$ENV{PAR_TEMP} ||= File::Spec->catdir(File::Spec->tmpdir, 'par'); -mkdir $ENV{PAR_TEMP}, 0777; -%escapes = map { chr($_) => sprintf("%%%02X", $_) } 0..255 unless %escapes; -$args{dist} =~ s{^cpan://((([a-zA-Z])[a-zA-Z])[-_a-zA-Z]+)/} -{http://www.cpan.org/modules/by-authors/id/\U$3/$2/$1\E/}; -my $file = $args{dist}; -$file =~ s/([^\w\.])/$escapes{$1}/g; -$file = File::Spec->catfile( $ENV{PAR_TEMP}, $file); -my $rc = LWP::Simple::mirror( $args{dist}, $file ); -if (!LWP::Simple::is_success($rc) and $rc != 304) { -die "Error $rc: ", LWP::Simple::status_message($rc), " ($args{dist})\n"; -} -return $file if -e $file; -return; -} -sub _verify_or_sign { -my %args = &_args; -require File::Path; -require Module::Signature; -die "Module::Signature version 0.25 required" -unless Module::Signature->VERSION >= 0.25; -require Cwd; -my $cwd = Cwd::cwd(); -my $action = $args{action}; -my ($dist, $tmpdir) = _unzip_to_tmpdir($args{dist}); -$action ||= (-e 'SIGNATURE' ? 'verify' : 'sign'); -if ($action eq 'sign') { -open FH, '>SIGNATURE' unless -e 'SIGNATURE'; -open FH, 'MANIFEST' or die $!; -local $/; -my $out = ; -if ($out !~ /^SIGNATURE(?:\s|$)/m) { -$out =~ s/^(?!\s)/SIGNATURE\n/m; -open FH, '>MANIFEST' or die $!; -print FH $out; -} -close FH; -$args{overwrite} = 1 unless exists $args{overwrite}; -$args{skip} = 0 unless exists $args{skip}; -} -my $rv = Module::Signature->can($action)->(%args); -_zip(dist => $dist) if $action eq 'sign'; -File::Path::rmtree([$tmpdir]); -chdir($cwd); -return $rv; -} -sub _unzip_to_tmpdir { -my %args = &_args; -require File::Temp; -my $dist = File::Spec->rel2abs($args{dist}); -my $tmpdirname = File::Spec->catdir(File::Spec->tmpdir, "parXXXXX"); -my $tmpdir = File::Temp::mkdtemp($tmpdirname) -or die "Could not create temporary directory from template '$tmpdirname': $!"; -my $path = $tmpdir; -$path = File::Spec->catdir($tmpdir, $args{subdir}) if defined $args{subdir}; -_unzip(dist => $dist, path => $path); -chdir $tmpdir; -return ($dist, $tmpdir); -} -sub parse_dist_name { -my $file = shift; -return(undef, undef, undef, undef) if not defined $file; -(undef, undef, $file) = File::Spec->splitpath($file); -my $version = qr/v?(?:\d+(?:_\d+)?|\d*(?:\.\d+(?:_\d+)?)+)/; -$file =~ s/\.(?:par|tar\.gz|tar)$//i; -my @elem = split /-/, $file; -my (@dn, $dv, @arch, $pv); -while (@elem) { -my $e = shift @elem; -if ( -$e =~ /^$version$/o -and not(# if not next token also a version -@elem and $elem[0] =~ /^$version$/o -) -) { -$dv = $e; -last; -} -push @dn, $e; -} -my $dn; -$dn = join('-', @dn) if @dn; -if (not @elem) { -return( $dn, $dv, undef, undef); -} -while (@elem) { -my $e = shift @elem; -if ($e =~ /^$version|any_version$/) { -$pv = $e; -last; -} -push @arch, $e; -} -my $arch; -$arch = join('-', @arch) if @arch; -return($dn, $dv, $arch, $pv); -} -sub generate_blib_stub { -my %args = &_args; -my $dist = $args{dist}; -require Config; -my $name = $args{name}; -my $version = $args{version}; -my $suffix = $args{suffix}; -my ($parse_name, $parse_version, $archname, $perlversion) -= parse_dist_name($dist); -$name ||= $parse_name; -$version ||= $parse_version; -$suffix = "$archname-$perlversion" -if (not defined $suffix or $suffix eq '') -and $archname and $perlversion; -$suffix ||= "$Config::Config{archname}-$Config::Config{version}"; -if ( grep { not defined $_ } ($name, $version, $suffix) ) { -warn "Could not determine distribution meta information from distribution name '$dist'"; -return(); -} -$suffix =~ s/\.par$//; -if (not -f 'META.yml') { -open META, '>', 'META.yml' -or die "Could not open META.yml file for writing: $!"; -print META << "YAML" if fileno(META); -name: $name -version: $version -build_requires: {} -conflicts: {} -dist_name: $name-$version-$suffix.par -distribution_type: par -dynamic_config: 0 -generated_by: 'PAR::Dist version $PAR::Dist::VERSION' -license: unknown -YAML -close META; -} -mkdir('blib'); -mkdir(File::Spec->catdir('blib', 'lib')); -mkdir(File::Spec->catdir('blib', 'script')); -return 1; -} -sub contains_binaries { -require File::Find; -my %args = &_args; -my $dist = $args{dist}; -return undef if not defined $dist or not -r $dist; -require Cwd; -require File::Path; -my $old_cwd = Cwd::cwd(); -(undef, my $base_dir) = _unzip_to_tmpdir( -dist => $dist, subdir => 'blib' -); -my $blibdir = File::Spec->catdir($base_dir, 'blib'); -my $archdir = File::Spec->catdir($blibdir, 'arch'); -my $found = 0; -File::Find::find( -sub { -$found++ if -f $_ and not /^\.exists$/; -}, -$archdir -); -chdir($old_cwd); -File::Path::rmtree([$base_dir]); -return $found ? 1 : 0; -} -1; diff --git a/test/expected_dir/perl_module.pm/perl/comment b/test/expected_dir/perl_module.pm/perl/comment deleted file mode 100644 index ee6abe8..0000000 --- a/test/expected_dir/perl_module.pm/perl/comment +++ /dev/null @@ -1,285 +0,0 @@ -=head1 NAME -PAR::Dist - Create and manipulate PAR distributions -=head1 VERSION -This document describes version 0.29 of PAR::Dist, released Feb 6, 2008. -=head1 SYNOPSIS -As a shell command: -% perl -MPAR::Dist -eblib_to_par -In programs: -use PAR::Dist; -my $dist = blib_to_par(); # make a PAR file using ./blib/ -install_par($dist); # install it into the system -uninstall_par($dist); # uninstall it from the system -sign_par($dist); # sign it using Module::Signature -verify_par($dist); # verify it using Module::Signature -install_par("http://foo.com/DBI-1.37-MSWin32-5.8.0.par"); # works too -install_par("http://foo.com/DBI-1.37"); # auto-appends archname + perlver -install_par("cpan://SMUELLER/PAR-Packer-0.975"); # uses CPAN author directory -=head1 DESCRIPTION -This module creates and manipulates I. They are -architecture-specific B files, containing everything under F -of CPAN distributions after their C or C stage, a -F describing metadata of the original CPAN distribution, -and a F detailing all files within it. Digitally signed PAR -distributions will also contain a F file. -The naming convention for such distributions is: -$NAME-$VERSION-$ARCH-$PERL_VERSION.par -For example, C corresponds to the -0.01 release of C on CPAN, built for perl 5.8.0 running on -C. -=head1 FUNCTIONS -Several functions are exported by default. Unless otherwise noted, -they can take either a hash of -named arguments, a single argument (taken as C<$path> by C -and C<$dist> by other functions), or no arguments (in which case -the first PAR file in the current directory is used). -Therefore, under a directory containing only a single F, all -invocations below are equivalent: -% perl -MPAR::Dist -e"install_par( dist => 'test.par' )" -% perl -MPAR::Dist -e"install_par( 'test.par' )" -% perl -MPAR::Dist -einstall_par; -If C<$dist> resembles a URL, C is called to mirror it -locally under C<$ENV{PAR_TEMP}> (or C<$TEMP/par/> if unspecified), and the -function will act on the fetched local file instead. If the URL begins -with C, it will be expanded automatically to the author's CPAN -directory (e.g. C). -If C<$dist> does not have a file extension beginning with a letter or -underscore, a dash and C<$suffix> ($ARCH-$PERL_VERSION.par by default) -will be appended to it. -=head2 blib_to_par -Takes key/value pairs as parameters or a single parameter indicating the -path that contains the F subdirectory. -Builds a PAR distribution from the F subdirectory under C, or -under the current directory if unspecified. If F does not exist, -it automatically runs F, F, F or F to -create it. -Returns the filename or the generated PAR distribution. -Valid parameters are: -=over 2 -=item path -Sets the path which contains the F subdirectory from which the PAR -distribution will be generated. -=item name, version, suffix -These attributes set the name, version and platform specific suffix -of the distribution. Name and version can be automatically -determined from the distributions F or F files. -The suffix is generated from your architecture name and your version of -perl by default. -=item dist -The output filename for the PAR distribution. -=back -=cut -# don't use 'my $foo ... if ...' it creates a static variable! -# could not determine name or version. Error. -=head2 install_par -Installs a PAR distribution into the system, using -C. -Valid parameters are: -=over 2 -=item dist -The .par file to install. The heuristics outlined in the B -section above apply. -=item prefix -This string will be prepended to all installation paths. -If it isn't specified, the environment variable -C is used as a prefix. -=back -Additionally, you can use several parameters to change the default -installation destinations. You don't usually have to worry about this -unless you are installing into a user-local directory. -The following section outlines the parameter names and default settings: -Parameter From To -inst_lib blib/lib $Config{installsitelib} (*) -inst_archlib blib/arch $Config{installsitearch} -inst_script blib/script $Config{installscript} -inst_bin blib/bin $Config{installbin} -inst_man1dir blib/man1 $Config{installman1dir} -inst_man3dir blib/man3 $Config{installman3dir} -packlist_read $Config{sitearchexp}/auto/$name/.packlist -packlist_write $Config{installsitearch}/auto/$name/.packlist -The C parameter is used to control where the F<.packlist> -file is written to. (Necessary for uninstallation.) -The C parameter specifies a .packlist file to merge in if -it exists. By setting any of the above installation targets to C, -you can remove that target altogether. For example, passing -C undef, inst_man3dir => undef> means that the contained -manual pages won't be installed. This is not available for the packlists. -Finally, you may specify a C parameter. Its value should be -a reference to a hash of custom installation targets such as -custom_targets => { 'blib/my_data' => '/some/path/my_data' } -You can use this to install the F<.par> archives contents to arbitrary -locations. -If only a single parameter is given, it is treated as the C -parameter. -=cut -=head2 uninstall_par -Uninstalls all previously installed contents of a PAR distribution, -using C. -Takes almost the same parameters as C, but naturally, -the installation target parameters do not apply. The only exception -to this is the C parameter which specifies the -F<.packlist> file to read the list of installed files from. -It defaults to C<$Config::Config{installsitearch}/auto/$name/.packlist>. -=cut -# Returns the default installation target as used by -# ExtUtils::Install::install(). First parameter should be the base -# directory containing the blib/ we're installing from. -# Second parameter should be the name of the distribution for the packlist -# paths. Third parameter may be a hash reference with user defined keys for -# the target hash. In fact, any contents that do not start with 'inst_' are -# skipped. -# accepted sources (and user overrides) -# default targets -# Included for future support for ${flavour}perl external lib installation -# if ($Config::Config{flavour_perl}) { -# my $ext = File::Spec->catdir($dir, 'blib', 'ext'); -# # from => to -# $sources{inst_external_lib} = File::Spec->catdir($ext, 'lib'); -# $sources{inst_external_bin} = File::Spec->catdir($ext, 'bin'); -# $sources{inst_external_include} = File::Spec->catdir($ext, 'include'); -# $sources{inst_external_src} = File::Spec->catdir($ext, 'src'); -# $target->{ $sources{inst_external_lib} } = $Config::Config{flavour_install_lib}; -# $target->{ $sources{inst_external_bin} } = $Config::Config{flavour_install_bin}; -# $target->{ $sources{inst_external_include} } = $Config::Config{flavour_install_include}; -# $target->{ $sources{inst_external_src} } = $Config::Config{flavour_install_src}; -# } -# insert user overrides -# undef means "remove" -# overwrite stuff, don't let the user create new entries -=head2 sign_par -Digitally sign a PAR distribution using C or B, -via B. -=cut -=head2 verify_par -Verify the digital signature of a PAR distribution using C or -B, via B. -Returns a boolean value indicating whether verification passed; C<$!> -is set to the return code of C. -=cut -=head2 merge_par -Merge two or more PAR distributions into one. First argument must -be the name of the distribution you want to merge all others into. -Any following arguments will be interpreted as the file names of -further PAR distributions to merge into the first one. -merge_par('foo.par', 'bar.par', 'baz.par') -This will merge the distributions C, C and C -into the distribution C. C will be overwritten! -The original META.yml of C is retained. -=cut -# parameter checking -# The unzipping will change directories. Remember old dir. -# Unzip the base par to a temp. dir. -# move the META.yml to the (main) temp. dir. -# delete (incorrect) MANIFEST -# extract additional pars and merge -# restore original directory because the par path -# might have been relative! -# I hate File::Find -# And I hate writing portable code, too. -# merge directory structure -# merge files -# delete (copied) MANIFEST and META.yml -=head2 remove_man -Remove the man pages from a PAR distribution. Takes one named -parameter: I which should be the name (and path) of the -PAR distribution file. The calling conventions outlined in -the C section above apply. -The PAR archive will be -extracted, stripped of all C and C subdirectories -and then repackaged into the original file. -=cut -# parameter checking -# The unzipping will change directories. Remember old dir. -# Unzip the base par to a temp. dir. -# move the META.yml to the (main) temp. dir. -# delete (incorrect) MANIFEST -=head2 get_meta -Opens a PAR archive and extracts the contained META.yml file. -Returns the META.yml file as a string. -Takes one named parameter: I. If only one parameter is -passed, it is treated as the I parameter. (Have a look -at the description in the C section above.) -Returns undef if no PAR archive or no META.yml within the -archive were found. -=cut -# The unzipping will change directories. Remember old dir. -# Unzip the base par to a temp. dir. -# Try fast unzipping first -# Then slow unzipping -# Then fall back to the system -# This sub munges the arguments to most of the PAR::Dist functions -# into a hash. On the way, it downloads PAR archives as necessary, etc. -# default to the first .par in the CWD -# single argument => it's a distribution file name or URL -# If we are installing from an URL, we want to munge the -# distribution name so that it is in form "Module-Name" -# @elems is name, version, arch, perlversion -# append suffix if there is none -# download if it's an URL -# Download PAR archive, but only if necessary (mirror!) -=head2 parse_dist_name -First argument must be a distribution file name. The file name -is parsed into I, I, -I, and I. -Returns the results as a list in the above order. -If any or all of the above cannot be determined, returns undef instead -of the undetermined elements. -Supported formats are: -Math-Symbolic-0.502-x86_64-linux-gnu-thread-multi-5.8.7 -Math-Symbolic-0.502 -The ".tar.gz" or ".par" extensions as well as any -preceding paths are stripped before parsing. Starting with C -0.22, versions containing a preceding C are parsed correctly. -This function is not exported by default. -=cut -# (assumes an arch string doesnt start with a version...) -=head2 generate_blib_stub -Creates a F subdirectory in the current directory -and prepares a F with meta information for a -new PAR distribution. First argument should be the name of the -PAR distribution in a format understood by C. -Alternatively, named arguments resembling those of -C are accepted. -After running C and injecting files into -the F directory, you can create a PAR distribution -using C. -This function is useful for creating custom PAR distributions -from scratch. (I.e. not from an unpacked CPAN distribution) -Example: -use PAR::Dist; -use File::Copy 'copy'; -generate_blib_stub( -name => 'MyApp', version => '1.00' -); -copy('MyApp.pm', 'blib/lib/MyApp.pm'); -blib_to_par(); # generates the .par file! -C will not overwrite existing files. -=cut -=head2 contains_binaries -This function is not exported by default. -Opens a PAR archive tries to determine whether that archive -contains platform-specific binary code. -Takes one named parameter: I. If only one parameter is -passed, it is treated as the I parameter. (Have a look -at the description in the C section above.) -Throws a fatal error if the PAR archive could not be found. -Returns one if the PAR was found to contain binary code -and zero otherwise. -=cut -# The unzipping will change directories. Remember old dir. -# Unzip the base par to a temp. dir. -=head1 SEE ALSO -L, L, L, L -=head1 AUTHORS -Audrey Tang Ecpan@audreyt.orgE 2003-2007 -Steffen Mueller Esmueller@cpan.orgE 2005-2007 -PAR has a mailing list, Epar@perl.orgE, that you can write to; -send an empty mail to Epar-subscribe@perl.orgE to join the list -and participate in the discussion. -Please send bug reports to Ebug-par@rt.cpan.orgE. -=head1 COPYRIGHT -Copyright 2003-2007 by Audrey Tang Eautrijus@autrijus.orgE. -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. -See L -=cut diff --git a/test/expected_dir/perl_pod_to_eof.pl b/test/expected_dir/perl_pod_to_eof.pl new file mode 100644 index 0000000..4f2b850 --- /dev/null +++ b/test/expected_dir/perl_pod_to_eof.pl @@ -0,0 +1 @@ +perl comment =head NAME diff --git a/test/expected_dir/php1.php b/test/expected_dir/php1.php new file mode 100644 index 0000000..a9d85ec --- /dev/null +++ b/test/expected_dir/php1.php @@ -0,0 +1,59 @@ +html code +html code +html code +html code +html code +html code +html code +html code +html code +html code +html code +html code +html code
FirstLastEmail +html code
+html blank +html code +html blank +html code +php code +php code +php code +html code +html code +html blank +html code +html blank +html code diff --git a/test/expected_dir/php1.php/css/code b/test/expected_dir/php1.php/css/code deleted file mode 100644 index b42db9a..0000000 --- a/test/expected_dir/php1.php/css/code +++ /dev/null @@ -1,3 +0,0 @@ -h1 { -color: black; -} diff --git a/test/expected_dir/php1.php/css/comment b/test/expected_dir/php1.php/css/comment deleted file mode 100644 index 5912a96..0000000 --- a/test/expected_dir/php1.php/css/comment +++ /dev/null @@ -1 +0,0 @@ -/* css comment */ diff --git a/test/expected_dir/php1.php/html/blanks b/test/expected_dir/php1.php/html/blanks deleted file mode 100644 index bf0d87a..0000000 --- a/test/expected_dir/php1.php/html/blanks +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/test/expected_dir/php1.php/html/code b/test/expected_dir/php1.php/html/code deleted file mode 100644 index a7114ab..0000000 --- a/test/expected_dir/php1.php/html/code +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - -
FirstLastEmail -
- - - - - - diff --git a/test/expected_dir/php1.php/javascript/code b/test/expected_dir/php1.php/javascript/code deleted file mode 100644 index b14f5c0..0000000 --- a/test/expected_dir/php1.php/javascript/code +++ /dev/null @@ -1 +0,0 @@ -document.write("Hello World!") diff --git a/test/expected_dir/php1.php/javascript/comment b/test/expected_dir/php1.php/javascript/comment deleted file mode 100644 index ecd132d..0000000 --- a/test/expected_dir/php1.php/javascript/comment +++ /dev/null @@ -1 +0,0 @@ -// javascript comment diff --git a/test/expected_dir/php1.php/php/code b/test/expected_dir/php1.php/php/code deleted file mode 100644 index f967d78..0000000 --- a/test/expected_dir/php1.php/php/code +++ /dev/null @@ -1,16 +0,0 @@ -mysql_connect("localhost", "db user", "db pass") -or die("DB CONNECT ERROR: " . mysql_error()); -mysql_select_db("db name") -or die("DB SELECT ERROR: " . mysql_error()); -$query = "SELECT fname, lname, email FROM table ORDER BY lname"; -$result = mysql_query($query) -or die("DB SELECT ERROR: " . mysql_error()); -while($row = mysql_fetch_array($result)) -{ -$lname = $row['lname']; -$fname = $row['fname']; -$email = $row['email']; - - - -} // end while diff --git a/test/expected_dir/php1.php/php/comment b/test/expected_dir/php1.php/php/comment deleted file mode 100644 index 3a86eb9..0000000 --- a/test/expected_dir/php1.php/php/comment +++ /dev/null @@ -1,3 +0,0 @@ -## Comment with a hash symbol ## -// Spaghetti code starts....(slopping html code in) -// Spaghetti code is both a source of praise and complaints diff --git a/test/expected_dir/pike1.pike b/test/expected_dir/pike1.pike new file mode 100644 index 0000000..73b3cf7 --- /dev/null +++ b/test/expected_dir/pike1.pike @@ -0,0 +1,6 @@ +pike code #!/bin/env pike +pike comment /* Say hello. */ +pike code int main(int argc, array(string) argv) +pike code { +pike code Stdio.stdout.write("Hello, world.\n"); +pike code } diff --git a/test/expected_dir/pike1.pike/pike/blanks b/test/expected_dir/pike1.pike/pike/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/pike1.pike/pike/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/pike1.pike/pike/code b/test/expected_dir/pike1.pike/pike/code deleted file mode 100644 index 6f52ddd..0000000 --- a/test/expected_dir/pike1.pike/pike/code +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/env pike -int main(int argc, array(string) argv) -{ -Stdio.stdout.write("Hello, world.\n"); -} diff --git a/test/expected_dir/pike1.pike/pike/comment b/test/expected_dir/pike1.pike/pike/comment deleted file mode 100644 index 8fda75e..0000000 --- a/test/expected_dir/pike1.pike/pike/comment +++ /dev/null @@ -1 +0,0 @@ -/* Say hello. */ diff --git a/test/expected_dir/pike2.pmod b/test/expected_dir/pike2.pmod new file mode 100644 index 0000000..2305875 --- /dev/null +++ b/test/expected_dir/pike2.pmod @@ -0,0 +1,241 @@ +pike comment // +pike comment // LPD.pmod: an implementation of the BSD lpd protocol (RFC 1179). +pike comment // This is a module for pike. +pike comment // 3 July 1998 Bill Welliver +pike comment // +pike comment // $Id: LPD.pmod,v 1.10 2008/01/13 17:02:43 nilsson Exp $ +pike comment // +pike blank +pike code #pike __REAL_VERSION__ +pike blank +pike comment //! A client for communicating with printers and print spoolers that +pike comment //! support the BSD lpd protocol (RFC 1179). +pike code class client { +pike code string host; +pike code int port; +pike code private object conn; +pike code int jobnum; +pike code string jobtype; +pike code string jobname; +pike blank +pike code private int connect(string host, int port) +pike code { +pike code int a=random(10); +pike comment // try to open one of the "official" local socket ports. +pike comment // not having one doesn't seem to be a problem with most LPD +pike comment // servers, but we should at least try. will probably fail +pike comment // if two try to open the same local port at once. ymmv. +pike code int res=conn->open_socket(721 + a); +pike blank +pike code return conn->connect(host, port); +pike code } +pike blank +pike comment //! @decl int set_job_type(string type) +pike comment //! Set the type of job to be sent to the printer to @i{type@}. +pike comment //! Valid types are: text, postscript and raw. +pike code int set_job_type(string type) +pike code { +pike code type=lower_case(type); +pike blank +pike code switch (type) { +pike code case "f": +pike code case "text": +pike code jobtype="f"; +pike code break; +pike blank +pike code case "o": +pike code case "postscript": +pike code case "ps": +pike code jobtype="o"; +pike code break; +pike blank +pike code default: +pike code case "l": +pike code case "raw": +pike code jobtype="l"; +pike code break; +pike code } +pike code return 1; +pike code } +pike blank +pike comment //! @decl int set_job_name(string name) +pike comment //! Sets the name of the print job to @i{name@}. +pike code int set_job_name(string name) +pike code { +pike code jobname=name; +pike code return 1; +pike code } +pike blank +pike comment //! @decl int start_queue(string queue) +pike comment //! Start the queue @i{queue@} if not already printing. +pike comment //! @returns +pike comment //! Returns 0 if unable to connect, 1 otherwise. +pike code int start_queue(string queue) +pike code { +pike code if(!queue) return 0; +pike blank +pike code if(!connect(host, port)) +pike code return 0; +pike blank +pike code conn->write(sprintf("%c%s\n", 01, queue)); +pike code string resp= conn->read(); +pike code conn->close(); +pike code return 1; +pike code } +pike blank +pike comment //! @decl string|int send_job(string queue, string job) +pike comment //! Send print job consisting of data @i{job@} to printer @i{queue@}. +pike comment //! @returns +pike comment //! Returns 1 if success, 0 otherwise. +pike code int send_job(string queue, string job) +pike code { +pike code string resp; +pike blank +pike code if(!queue) return 0; +pike blank +pike code if(!connect(host, port)) +pike code return 0; +pike comment // werror("connected to " + host + "\n"); +pike blank +pike code string control=""; +pike code control+="H"+gethostname()+"\n"; +pike code #if constant(getuid) && constant(getpwuid) +pike code control+="P"+(getpwuid(getuid())[0]||"nobody")+"\n"; +pike code #else +pike code control+="P-1\n"; +pike code #endif +pike code control+=(jobtype||"l")+"dfA"+ sprintf("%03d%s", jobnum, gethostname())+"\n"; +pike code if(jobname) +pike code { +pike code control+="J" + jobname + "\n"; +pike code control+="N" + jobname + "\n"; +pike code } +pike code else +pike code { +pike code control+="JPike LPD Client Job " + jobnum + "\n"; +pike code control+="NPike LPD Client Job " + jobnum + "\n"; +pike code } +pike code jobnum++; +pike code werror("job file:\n\n" + control + "\n\n"); +pike blank +pike code conn->write(sprintf("%c%s\n", 02, queue)); +pike code resp=conn->read(1); +pike code if((int)resp !=0) +pike code { +pike code werror("receive job failed.\n"); +pike code return 0; +pike code } +pike blank +pike code conn->write(sprintf("%c%s cfA%03d%s\n", 02, (string)sizeof(control), +pike code jobnum,gethostname())); +pike blank +pike code resp=conn->read(1); +pike code if((int)resp !=0) +pike code { +pike code werror("request receive control failed.\n"); +pike code return 0; +pike code } +pike blank +pike code conn->write(sprintf("%s%c", control, 0)); +pike blank +pike code resp=conn->read(1); +pike code if((int)resp !=0) +pike code { +pike code werror("send receive control failed.\n"); +pike code return 0; +pike code } +pike blank +pike code conn->write(sprintf("%c%s dfA%03d%s\n", 03, (string)sizeof(job), jobnum, +pike code gethostname())); +pike code resp=conn->read(1); +pike code if((int)resp !=0) +pike code { +pike code werror("request receive job failed.\n"); +pike code return 0; +pike code } +pike blank +pike blank +pike code conn->write(sprintf("%s%c", job, 0)); +pike blank +pike code resp=conn->read(1); +pike code if((int)resp !=0) +pike code { +pike code werror("send receive job failed.\n"); +pike code return 0; +pike code } +pike blank +pike blank +pike blank +pike comment // read the response. +pike blank +pike comment // resp=conn->read(); +pike code if((int)(resp)!=0) +pike code { +pike code conn->close(); +pike code return 0; +pike code } +pike code conn->close(); +pike comment // start_queue(queue); +pike code return 1; +pike code } +pike blank +pike comment //! @decl int delete_job(string queue, int|void job) +pike comment //! Delete job @i{job@} from printer @i{queue@}. +pike comment //! @returns +pike comment //! Returns 1 on success, 0 otherwise. +pike code int delete_job(string queue, int|void job) +pike code { +pike code if(!queue) return 0; +pike blank +pike code if(!connect(host, port)) +pike code return 0; +pike blank +pike code #if constant(getpwuid) && constant(getuid) +pike code string agent=(getpwuid(getuid())[0]||"nobody"); +pike code #else +pike code string agent="nobody"; +pike code #endif +pike blank +pike code if(job) +pike code conn->write(sprintf("%c%s %s %d\n", 05, queue, agent, job)); +pike code else +pike code conn->write(sprintf("%c%s %s\n", 05, queue, agent)); +pike code string resp= conn->read(); +pike code conn->close(); +pike code return 1; +pike code } +pike blank +pike blank +pike comment //! @decl string|int status(string queue) +pike comment //! Check the status of queue @i{queue@}. +pike comment //! @returns +pike comment //! Returns 0 on failure, otherwise returns the status response from the printer. +pike code string|int status(string queue) +pike code { +pike code if(!queue) return 0; +pike blank +pike code if(!connect(host, port)) +pike code return 0; +pike blank +pike code conn->write(sprintf("%c%s\n", 04, queue)); +pike code string resp= conn->read(); +pike code conn->close(); +pike code return resp; +pike code } +pike blank +pike comment //! Create a new LPD client connection. +pike comment //! @param hostname +pike comment //! Contains the hostname or ipaddress of the print host. +pike comment //! if not provided, defaults to @i{localhost@}. +pike comment //! @param portnum +pike comment //! Contains the port the print host is listening on. +pike comment //! if not provided, defaults to port @i{515@}, the RFC 1179 standard. +pike code void create(string|void hostname, int|void portnum) +pike code { +pike code host=hostname || "localhost"; +pike code port=portnum || 515; +pike code conn=Stdio.File(); +pike code jobnum=1; +pike code } +pike code } +pike blank diff --git a/test/expected_dir/pike2.pmod/pike/blanks b/test/expected_dir/pike2.pmod/pike/blanks deleted file mode 100644 index 72f523f..0000000 --- a/test/expected_dir/pike2.pmod/pike/blanks +++ /dev/null @@ -1 +0,0 @@ -39 \ No newline at end of file diff --git a/test/expected_dir/pike2.pmod/pike/code b/test/expected_dir/pike2.pmod/pike/code deleted file mode 100644 index a6f3edb..0000000 --- a/test/expected_dir/pike2.pmod/pike/code +++ /dev/null @@ -1,157 +0,0 @@ -#pike __REAL_VERSION__ -class client { -string host; -int port; -private object conn; -int jobnum; -string jobtype; -string jobname; -private int connect(string host, int port) -{ -int a=random(10); -int res=conn->open_socket(721 + a); -return conn->connect(host, port); -} -int set_job_type(string type) -{ -type=lower_case(type); -switch (type) { -case "f": -case "text": -jobtype="f"; -break; -case "o": -case "postscript": -case "ps": -jobtype="o"; -break; -default: -case "l": -case "raw": -jobtype="l"; -break; -} -return 1; -} -int set_job_name(string name) -{ -jobname=name; -return 1; -} -int start_queue(string queue) -{ -if(!queue) return 0; -if(!connect(host, port)) -return 0; -conn->write(sprintf("%c%s\n", 01, queue)); -string resp= conn->read(); -conn->close(); -return 1; -} -int send_job(string queue, string job) -{ -string resp; -if(!queue) return 0; -if(!connect(host, port)) -return 0; -string control=""; -control+="H"+gethostname()+"\n"; -#if constant(getuid) && constant(getpwuid) -control+="P"+(getpwuid(getuid())[0]||"nobody")+"\n"; -#else -control+="P-1\n"; -#endif -control+=(jobtype||"l")+"dfA"+ sprintf("%03d%s", jobnum, gethostname())+"\n"; -if(jobname) -{ -control+="J" + jobname + "\n"; -control+="N" + jobname + "\n"; -} -else -{ -control+="JPike LPD Client Job " + jobnum + "\n"; -control+="NPike LPD Client Job " + jobnum + "\n"; -} -jobnum++; -werror("job file:\n\n" + control + "\n\n"); -conn->write(sprintf("%c%s\n", 02, queue)); -resp=conn->read(1); -if((int)resp !=0) -{ -werror("receive job failed.\n"); -return 0; -} -conn->write(sprintf("%c%s cfA%03d%s\n", 02, (string)sizeof(control), -jobnum,gethostname())); -resp=conn->read(1); -if((int)resp !=0) -{ -werror("request receive control failed.\n"); -return 0; -} -conn->write(sprintf("%s%c", control, 0)); -resp=conn->read(1); -if((int)resp !=0) -{ -werror("send receive control failed.\n"); -return 0; -} -conn->write(sprintf("%c%s dfA%03d%s\n", 03, (string)sizeof(job), jobnum, -gethostname())); -resp=conn->read(1); -if((int)resp !=0) -{ -werror("request receive job failed.\n"); -return 0; -} -conn->write(sprintf("%s%c", job, 0)); -resp=conn->read(1); -if((int)resp !=0) -{ -werror("send receive job failed.\n"); -return 0; -} -if((int)(resp)!=0) -{ -conn->close(); -return 0; -} -conn->close(); -return 1; -} -int delete_job(string queue, int|void job) -{ -if(!queue) return 0; -if(!connect(host, port)) -return 0; -#if constant(getpwuid) && constant(getuid) -string agent=(getpwuid(getuid())[0]||"nobody"); -#else -string agent="nobody"; -#endif -if(job) -conn->write(sprintf("%c%s %s %d\n", 05, queue, agent, job)); -else -conn->write(sprintf("%c%s %s\n", 05, queue, agent)); -string resp= conn->read(); -conn->close(); -return 1; -} -string|int status(string queue) -{ -if(!queue) return 0; -if(!connect(host, port)) -return 0; -conn->write(sprintf("%c%s\n", 04, queue)); -string resp= conn->read(); -conn->close(); -return resp; -} -void create(string|void hostname, int|void portnum) -{ -host=hostname || "localhost"; -port=portnum || 515; -conn=Stdio.File(); -jobnum=1; -} -} diff --git a/test/expected_dir/pike2.pmod/pike/comment b/test/expected_dir/pike2.pmod/pike/comment deleted file mode 100644 index 737f3d4..0000000 --- a/test/expected_dir/pike2.pmod/pike/comment +++ /dev/null @@ -1,45 +0,0 @@ -// -// LPD.pmod: an implementation of the BSD lpd protocol (RFC 1179). -// This is a module for pike. -// 3 July 1998 Bill Welliver -// -// $Id: LPD.pmod,v 1.10 2008/01/13 17:02:43 nilsson Exp $ -// -//! A client for communicating with printers and print spoolers that -//! support the BSD lpd protocol (RFC 1179). -// try to open one of the "official" local socket ports. -// not having one doesn't seem to be a problem with most LPD -// servers, but we should at least try. will probably fail -// if two try to open the same local port at once. ymmv. -//! @decl int set_job_type(string type) -//! Set the type of job to be sent to the printer to @i{type@}. -//! Valid types are: text, postscript and raw. -//! @decl int set_job_name(string name) -//! Sets the name of the print job to @i{name@}. -//! @decl int start_queue(string queue) -//! Start the queue @i{queue@} if not already printing. -//! @returns -//! Returns 0 if unable to connect, 1 otherwise. -//! @decl string|int send_job(string queue, string job) -//! Send print job consisting of data @i{job@} to printer @i{queue@}. -//! @returns -//! Returns 1 if success, 0 otherwise. -// werror("connected to " + host + "\n"); -// read the response. -// resp=conn->read(); -// start_queue(queue); -//! @decl int delete_job(string queue, int|void job) -//! Delete job @i{job@} from printer @i{queue@}. -//! @returns -//! Returns 1 on success, 0 otherwise. -//! @decl string|int status(string queue) -//! Check the status of queue @i{queue@}. -//! @returns -//! Returns 0 on failure, otherwise returns the status response from the printer. -//! Create a new LPD client connection. -//! @param hostname -//! Contains the hostname or ipaddress of the print host. -//! if not provided, defaults to @i{localhost@}. -//! @param portnum -//! Contains the port the print host is listening on. -//! if not provided, defaults to port @i{515@}, the RFC 1179 standard. diff --git a/test/expected_dir/prolog.pl b/test/expected_dir/prolog.pl new file mode 100644 index 0000000..f009dba --- /dev/null +++ b/test/expected_dir/prolog.pl @@ -0,0 +1,9 @@ +prolog comment /* test file for Prolog parsing */ +prolog blank +prolog comment % this is a Prolog source file +prolog blank +prolog comment % select(Element, List, Remaining) +prolog blank +prolog code select(H, [H| T], T). +prolog code select(H, [X| R], [X| T]) :- +prolog code select(H, R, T). diff --git a/test/expected_dir/puppet1.pp b/test/expected_dir/puppet1.pp new file mode 100644 index 0000000..cbb3d94 --- /dev/null +++ b/test/expected_dir/puppet1.pp @@ -0,0 +1,145 @@ +puppet code class bob::open_ldap { +puppet blank +puppet code define foo::server ( +puppet code $argsfile = undef, +puppet code $bdb_cachesize = '', +puppet code $bdb_checkpoint = '', +puppet code $bdb_directory = undef, +puppet code $bdb_idlcachesize = '', +puppet code $bdb_rootdn, +puppet code $bdb_rootpw, +puppet code $bdb_shm_key = '', +puppet code $bdb_suffix, +puppet code $conf_path = undef, +puppet code $conf_dir = undef, +puppet code $enable = false, +puppet code $include = [], +puppet code $includepath = undef, +puppet code $modulepath = '', +puppet code $modules = [], +puppet code $package = undef, +puppet code $pidfile = undef, +puppet code $sysconf_path = undef +puppet code ) { +puppet blank +puppet code $resource_name = "bob_openldap_server" +puppet blank +puppet code if($name != "params") { +puppet code fail("${resource_name}: This function is a singleton. Make sure the resource name is 'params'.") +puppet code } +puppet blank +puppet code case $operatingsystem { +puppet code Fedora: { +puppet code case $operatingsystemrelease { +puppet code /^(12|13)$/: { +puppet code if(!$argsfile) { $_argsfile = "/var/run/openldap/slapd.args" } +puppet code if(!$bdb_directory) { $_bdb_directory = "/var/lib/ldap" } +puppet code if(!$conf_path) { $_conf_path = "/etc/openldap/slapd.conf" } +puppet code if(!$conf_dir) { $_conf_dir = "/etc/openldap/slapd.d" } +puppet code if(!$package) { $_package = ["openldap-servers"] } +puppet code if(!$pidfile) { $_pidfile = "/var/run/openldap/slapd.pid" } +puppet code if(!$service) { $_service = "slapd" } +puppet code if(!$sysconf_path) { $_sysconf_path = "/etc/sysconfig/ldap" } +puppet code } +puppet code } +puppet code } +puppet code } +puppet blank +puppet comment # Presume the OS did not match and because these args are necessary, just +puppet comment # bail with an error. +puppet code if(!($_argsfile and $_bdb_directory and $_pidfile and $_conf_path and +puppet code $_package and $_service and $_sysconf_path and $_conf_dir)) { +puppet code fail("${resource_name}: Unsupported operating system: ${operatingsystem} version ${operatingsystemrelease} and you have not setup the args for: argsfile, bdb_directory, conf_dir, conf_path, package, pidfile, sysconf_path and service.") +puppet code } +puppet blank +puppet comment # Fix paths - add forward slashes at the end of strings without them +puppet code $_includepath = regsubst($includepath, '([^/])$', '\1/') +puppet code $_dbconf_path = "${_bdb_directory}/DB_CONFIG" +puppet blank +puppet comment # ... +puppet code file { +puppet code $_conf_path: +puppet code content => template("bob_openldap/slapd.conf"), +puppet code require => Package[$_package], +puppet code owner => "ldap", +puppet code group => "root", +puppet code mode => "0440", +puppet code notify => Service[$_service]; +puppet code $_sysconf_path: +puppet code content => template("bob_openldap/ldap.sysconf"), +puppet code require => Package[$_package], +puppet code owner => "root", +puppet code group => "root", +puppet code mode => "0644"; +puppet code $_conf_dir: +puppet code force => true, +puppet code ensure => absent, +puppet code before => Service[$_service]; +puppet code $_dbconf_path: +puppet code content => "", +puppet code notify => Service[$_service]; +puppet code } +puppet code package { +puppet code $_package: +puppet code ensure => installed; +puppet code } +puppet code service { +puppet code $_service: +puppet code ensure => $enable ? { +puppet code true => "running", +puppet code false => "stopped" +puppet code }, +puppet code enable => $enable, +puppet code hasstatus => true, +puppet code require => [ Package[$_package], File[$_conf_path] ]; +puppet code } +puppet code } +puppet blank +puppet code define client ( +puppet code $base, +puppet code $network_timeout = '', +puppet code $path = undef, +puppet code $timeout = '', +puppet code $binddn = '', +puppet code $tls_cacertdir = undef, +puppet code $uri +puppet code ) { +puppet blank +puppet code $resource_name = "bob_openldap_client" +puppet blank +puppet code if($name != "params") { +puppet code fail("${resource_name}: This function is a singleton. Make sure the resource name is 'params'.") +puppet code } +puppet blank +puppet code case $operatingsystem { +puppet code Fedora: { +puppet code case $operatingsystemrelease { +puppet code /^(12|13)$/: { +puppet code if(!$tls_cacertdir) { $_tls_cacertdir = "/etc/openldap/cacerts" } +puppet code if(!$path) { $_path = "/etc/openldap/ldap.conf" } +puppet code } +puppet code } +puppet code } +puppet code } +puppet blank +puppet comment # Presume the OS did not match and because these args are necessary, just +puppet comment # bail with an error. +puppet code if(!($_tls_cacertdir and $_path)) { +puppet code fail("${resource_name}: Unsupported operating system: ${operatingsystem} version ${operatingsystemrelease} and you have not setup the args for: tls_cacertdir, path.") +puppet code } +puppet blank +puppet comment # Fix some vars, ready for templating +puppet code $_base = $base +puppet code $_binddn = $binddn +puppet code $_network_timeout = $network_timeout +puppet code $_timeout = $timeout +puppet code $_uri = $uri +puppet blank +puppet code file { +puppet code $_path: +puppet code content => template("bob_openldap/ldap.conf") +puppet code } +puppet blank +puppet code } +puppet blank +puppet code } diff --git a/test/expected_dir/py1.py b/test/expected_dir/py1.py new file mode 100644 index 0000000..2f600fb --- /dev/null +++ b/test/expected_dir/py1.py @@ -0,0 +1,18 @@ +python comment # some python code +python comment # lorem +python comment # ipsum +python comment # foo +python blank +python code class Foo: +python comment """ +python comment This is a foo class +python comment It doesn't do anything +python comment Therefore this doc comment is pointless +python comment """ +python blank +python code def __init__(self, bar): +python comment """short doc comment""" +python code print(bar) +python blank +python code def string(self): +python code print('This is a string') diff --git a/test/expected_dir/py1.py/python/blanks b/test/expected_dir/py1.py/python/blanks deleted file mode 100644 index e440e5c..0000000 --- a/test/expected_dir/py1.py/python/blanks +++ /dev/null @@ -1 +0,0 @@ -3 \ No newline at end of file diff --git a/test/expected_dir/py1.py/python/code b/test/expected_dir/py1.py/python/code deleted file mode 100644 index 9547930..0000000 --- a/test/expected_dir/py1.py/python/code +++ /dev/null @@ -1,5 +0,0 @@ -class Foo: -def __init__(self, bar): -print(bar) -def string(self): -print('This is a string') diff --git a/test/expected_dir/py1.py/python/comment b/test/expected_dir/py1.py/python/comment deleted file mode 100644 index ebaa411..0000000 --- a/test/expected_dir/py1.py/python/comment +++ /dev/null @@ -1,10 +0,0 @@ -# some python code -# lorem -# ipsum -# foo -""" -This is a foo class -It doesn't do anything -Therefore this doc comment is pointless -""" -"""short doc comment""" diff --git a/test/expected_dir/rebol.r b/test/expected_dir/rebol.r new file mode 100644 index 0000000..17baf19 --- /dev/null +++ b/test/expected_dir/rebol.r @@ -0,0 +1,59 @@ +rebol comment ;; ================================================= +rebol comment ;; Script: new-suffix.r +rebol comment ;; downloaded from: www.REBOL.org +rebol comment ;; on: 1-Jun-2011 +rebol comment ;; at: 21:19:08.38986 UTC +rebol comment ;; owner: carl [script library member who can update +rebol comment ;; this script] +rebol comment ;; ================================================= +rebol code REBOL [ +rebol code Title: "Change File Extensions (Suffix)" +rebol code File: %new-suffix.r +rebol code Author: "Carl Sassenrath" +rebol code Date: 25-Jan-2005 +rebol code Purpose: { +rebol code Change the file extension (suffix) for files with a specific extension. +rebol code For example, change all .txt files to .r files in the current directory. +rebol code Displays a list of changes before it makes them. +rebol code } +rebol code Warning: "Back up your files first, just in case!" +rebol code License: "BSD - Use at your own risk." +rebol code Library: [ +rebol code level: 'beginner +rebol code platform: 'all +rebol code type: [tool] +rebol code domain: [files] +rebol code tested-under: none +rebol code support: none +rebol code license: 'bsd +rebol code see-also: none +rebol code ] +rebol code ] +rebol blank +rebol code from-suffix: %.txt +rebol code to-suffix: %.r +rebol blank +rebol code bulk-rename: func [confirmed] [ +rebol code foreach file load %./ [ +rebol code if all [ +rebol code not find file #"/" ; (ignore directories) +rebol code from-suffix = find/last file #"." +rebol code ][ +rebol code new-file: copy file +rebol code append clear find/last new-file #"." to-suffix +rebol code either confirmed [ +rebol code print ["Renaming" file "to" new-file] +rebol code rename file new-file +rebol code ][ +rebol code print ["Will rename" file "to" new-file] +rebol code ] +rebol code ] +rebol code ] +rebol code ] +rebol blank +rebol code bulk-rename false +rebol code if not confirm "Are you sure you want to rename all those files?" [ +rebol code quit +rebol code ] +rebol code bulk-rename true +rebol code ask "Done. Press enter." diff --git a/test/expected_dir/rexx1.rex b/test/expected_dir/rexx1.rex new file mode 100644 index 0000000..ff945d4 --- /dev/null +++ b/test/expected_dir/rexx1.rex @@ -0,0 +1,311 @@ +rexx comment /* REXX FLTTBL Cloned from DUMPTBL 960619 to produce a flat +rexx comment version (up to 32K characters wide) of any ISPF +rexx comment table. +rexx blank +rexx comment Written by Frank Clarke, Oldsmar, FL +rexx blank +rexx comment Impact Analysis +rexx comment . SYSPROC LA +rexx comment . SYSPROC TRAPOUT +rexx blank +rexx comment Modification History +rexx comment 19960918 fxc added some error-checking +rexx comment 19970115 fxc upgrade REXXSKEL from v.960606 to v.970113; add +rexx comment RESTARTability; +rexx comment 19991231 fxc upgrade REXXSKEL from v.970113 to v.19991109; +rexx comment RXSKLY2K; DECOMM; LRECL reduced from 32K to "min +rexx comment needed"; +rexx blank +rexx code */ arg argline +rexx code address TSO /* REXXSKEL ver.19991109 */ +rexx code arg parms "((" opts +rexx blank +rexx code signal on syntax +rexx code signal on novalue +rexx blank +rexx code call TOOLKIT_INIT /* conventional start-up -*/ +rexx code rc = Trace(tv) +rexx code info = parms /* to enable parsing */ +rexx blank +rexx code if \sw.inispf then do +rexx code arg line +rexx code line = line "(( RESTARTED" /* tell the next invocation */ +rexx code "ISPSTART CMD("exec_name line")" /* Invoke ISPF if nec. */ +rexx code exit /* ...and restart it */ +rexx code end +rexx blank +rexx code call A_INIT /* -*/ +rexx blank +rexx code "NEWSTACK" +rexx code if \sw.0error_found then, +rexx code call C_TABLE_OPS /* -*/ +rexx code if \sw.0error_found then, +rexx code call D_PUMP_TBL /* -*/ +rexx blank +rexx code "DELSTACK" +rexx blank +rexx code if sw.restarted then do +rexx code rc = OutTrap("ll.") +rexx code exit 4 +rexx code end +rexx blank +rexx code exit /*@ FLTTBL */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code A_INIT: /*@ */ +rexx code if branch then call BRANCH +rexx code address TSO +rexx blank +rexx code call AA_KEYWDS /* -*/ +rexx code parse var info $tn$ . /* table-name required */ +rexx code if $tn$ = "" then do +rexx code helpmsg = "Tablename is required." +rexx code call HELP +rexx code end +rexx blank +rexx code parse value outdsn "FLATTBLS."$tn$ with, +rexx code outdsn . +rexx blank +rexx code xefef = "efef"x +rexx code if tblds = "" then do +rexx code call AB_FIND_LIBRARY /* -*/ +rexx code if tblds = "" then do +rexx code helpmsg = "Table" $tn$ "was not found in ISPTLIB. Please", +rexx code "restart specifying a library name as shown below." +rexx code call HELP /* ...and don't come back */ +rexx code end +rexx code end +rexx code else, +rexx code if Left(tblds,1) = "'" then tblds = Strip(tblds,,"'") +rexx code else tblds = Userid()"."tblds +rexx blank +rexx code return /*@ A_INIT */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code AA_KEYWDS: /*@ */ +rexx code if branch then call BRANCH +rexx code address TSO +rexx blank +rexx code tblds = KEYWD("IN") +rexx code outdsn = KEYWD("OUTPUT") +rexx code sortseq = KEYWD("SORT") +rexx code sw.0purge = SWITCH("DELETEBEHIND") +rexx blank +rexx code parse value KEYWD("ADD") "0" with bytes_to_add . +rexx blank +rexx code return /*@ AA_KEYWDS */ +rexx comment /* +rexx comment was not specified. Locate the table in ISPTLIB. +rexx comment . ----------------------------------------------------------------- */ +rexx code AB_FIND_LIBRARY: /*@ */ +rexx code if branch then call BRANCH +rexx code address TSO +rexx blank +rexx code "NEWSTACK" +rexx code "LA ISPTLIB ((STACK LINE" +rexx code pull tliblist +rexx code "DELSTACK" +rexx blank +rexx code do Words(tliblist) /* each library */ +rexx code parse var tliblist tblds tliblist +rexx code if Sysdsn("'"tblds"("$tn$")'") = "OK" then return +rexx code end /* tliblist */ +rexx code tblds = "" +rexx blank +rexx code return /*@ AB_FIND_LIBRARY */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code C_TABLE_OPS: /*@ */ +rexx code if branch then call BRANCH +rexx code address ISPEXEC +rexx blank +rexx code call CA_OPEN_TBL /* -*/ +rexx code call CS_SPIN_TBL /* -*/ +rexx code call CZ_DROP_TBL /* -*/ +rexx blank +rexx code return /*@ C_TABLE_OPS */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code CA_OPEN_TBL: /*@ */ +rexx code if branch then call BRANCH +rexx code address ISPEXEC +rexx blank +rexx code "LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" +rexx code "TBSTATS" $tn$ "STATUS1(s1) STATUS2(s2) ROWCURR(rowct)" +rexx code if s1 > 1 then do +rexx code say "Table" $tn$ "not available." +rexx code sw.0error_found = "1"; return +rexx code end; else, +rexx code if s2 = 1 then, /* not open */ +rexx code "TBOPEN " $tn$ "NOWRITE" +rexx code else "TBTOP" $tn$ +rexx code "LIBDEF ISPTLIB" +rexx code if sw.0error_found then return +rexx code "TBQUERY" $tn$ "KEYS(keylist)", +rexx code "NAMES(nmlist)" +rexx code parse var keylist "(" keylist ")" +rexx code parse var nmlist "(" nmlist ")" +rexx code namelist = keylist nmlist +rexx blank +rexx code if sortseq <> "" then "TBSORT" $tn$ "FIELDS("sortseq")" +rexx blank +rexx code return /*@ CA_OPEN_TBL */ +rexx comment /* +rexx comment . Given: contains all the defined names for this table. +rexx comment The table has been TOPped. +rexx comment . ----------------------------------------------------------------- */ +rexx code CS_SPIN_TBL: Procedure expose, /*@ hide everything */ +rexx code expose (tk_globalvars), /* except these */ +rexx code $tn$ namelist xefef tblds rows keylist nmlist maxlen +rexx code cs_tv = Trace() +rexx code if branch then call BRANCH +rexx code address ISPEXEC +rexx blank +rexx code maxlen = 0 /* maximum line length */ +rexx code do forever +rexx code "TBSKIP" $tn$ "SAVENAME(xvars)" +rexx code if rc > 0 then leave /* we're done... */ +rexx code line = "" /* set empty */ +rexx comment /* add blocks of "var .. varvalue .." */ +rexx code do cx = 1 to Words(namelist) +rexx code thiswd = Word(namelist,cx) +rexx code line = line thiswd xefef Value(thiswd) xefef +rexx code end /* cx */ +rexx code rc = Trace("O"); rc = Trace(cs_tv) +rexx code parse var xvars "(" xvars ")" +rexx comment /* add a block of "XVARS .. xvarlist .." */ +rexx code line = line "XVARS" xefef xvars xefef +rexx comment /* add blocks of "xvar .. xvarvalue .." */ +rexx code do cx = 1 to Words(xvars) +rexx code thiswd = Word(xvars,cx) +rexx code line = line thiswd xefef Value(thiswd) xefef +rexx code end /* cx */ +rexx code rc = Trace("O"); rc = Trace(cs_tv) +rexx code maxlen = Max(maxlen,Length(line)) +rexx code queue line +rexx code end /* forever */ +rexx blank +rexx code lines_in_stack = queued() +rexx code line = "Contents of" $tn$ "in" tblds, +rexx code "("lines_in_stack" rows) KEYS("keylist") NAMES("nmlist")." +rexx code push line /* make it the first line */ +rexx code maxlen = Max(maxlen,Length(line)) +rexx code if monitor then say "Maximum line length is" maxlen +rexx blank +rexx code return /*@ CS_SPIN_TBL */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code CZ_DROP_TBL: /*@ */ +rexx code if branch then call BRANCH +rexx code address ISPEXEC +rexx blank +rexx code if s2 = 1 then, /* table was not open at start*/ +rexx code "TBEND" $tn$ +rexx blank +rexx code return /*@ CZ_DROP_TBL */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code D_PUMP_TBL: /*@ */ +rexx code if branch then call BRANCH +rexx code address TSO +rexx blank +rexx code if monitor then say, +rexx code "Writing text." +rexx blank +rexx code maxlen = maxlen + 4 + bytes_to_add /* set LRECL */ +rexx code vbmax.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", +rexx code "RECFM(V B) LRECL("maxlen") BLKSIZE(0)" +rexx code vbmax.1 = "SHR" /* if it already exists... */ +rexx blank +rexx code tempstat = Sysdsn(outdsn) = "OK" /* 1=exists, 0=missing */ +rexx code "ALLOC FI($TMP) DA("outdsn") REU" vbmax.tempstat +rexx code rcx = rc +rexx code "EXECIO" queued() "DISKW $TMP (FINIS" +rexx code rcx = max(rcx,rc) +rexx code "FREE FI($TMP)" +rexx blank +rexx code if rcx = 0 & sw.0purge then do +rexx code address ISPEXEC +rexx code "LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" +rexx code "TBERASE" $tn$ +rexx code if rc = 0 then say $tn$ "was deleted" +rexx code "LIBDEF ISPTLIB" +rexx code end +rexx blank +rexx code return /*@ D_PUMP_TBL */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code LOCAL_PREINIT: /*@ customize opts */ +rexx code if branch then call BRANCH +rexx code address TSO +rexx blank +rexx blank +rexx code return /*@ LOCAL_PREINIT */ +rexx comment /* +rexx comment . ----------------------------------------------------------------- */ +rexx code HELP: /*@ */ +rexx code address TSO;"CLEAR" +rexx code if helpmsg <> "" then do ; say helpmsg; say ""; end +rexx code ex_nam = Left(exec_name,8) /* predictable size */ +rexx code say " "ex_nam" produces a flattened version of any ISPF table " +rexx code say " into a VB-form dataset of minimum necessary LRECL." +rexx code say " " +rexx code say " The field contents are written in KEYPHRS format " +rexx code say " (var .. varval ..) " +rexx code say " key-fields first, followed by name-fields, followed by the " +rexx code say " names of any extension variables key-phrased by 'XVARS', " +rexx code say " followed by the extension variables themselves in KEYPHRS " +rexx code say " format. " +rexx code say " " +rexx code say " The first record on the file identifies the table name, the " +rexx code say " source library, the number of rows processed, and the key- and " +rexx code say " name-fields. " +rexx code say " " +rexx code say " more.... " +rexx code pull +rexx code "CLEAR" +rexx code say " Syntax: "ex_nam" (Required)" +rexx code say " " +rexx code say " (Defaults)" +rexx code say " " +rexx code say " (Defaults)" +rexx code say " " +rexx code say " identifies the table to be dumped. " +rexx code say " " +rexx code say " identifies the ISPF Table library which holds ." +rexx code say " If is not specified, ISPTLIB will be " +rexx code say " searched to find the correct dataset. " +rexx code say " " +rexx code say " (default: FLATTBLS.) names the output file. " +rexx code say " will be created if it does not exist. " +rexx code say " " +rexx code say " causes the table to be sorted as indicated before " +rexx code say " being dumped. " +rexx code say " " +rexx code say " (default=0) causes the LRECL of the output dataset " +rexx code say " to be extended to enable updating. " +rexx code pull +rexx code "CLEAR" +rexx code say " Debugging tools provided include: " +rexx code say " " +rexx code say " MONITOR: displays key information throughout processing. " +rexx code say " Displays most paragraph names upon entry. " +rexx code say " " +rexx code say " NOUPDT: by-pass all update logic. " +rexx code say " " +rexx code say " BRANCH: show all paragraph entries. " +rexx code say " " +rexx code say " TRACE tv: will use value following TRACE to place the " +rexx code say " execution in REXX TRACE Mode. " +rexx code say " " +rexx code say " " +rexx code say " Debugging tools can be accessed in the following manner: " +rexx code say " " +rexx code say " TSO "ex_nam" parameters (( debug-options " +rexx code say " " +rexx code say " For example: " +rexx code say " " +rexx code say " TSO "ex_nam" vt2231 add 17 (( MONITOR TRACE ?R " +rexx code address ISPEXEC "CONTROL DISPLAY REFRESH" +rexx code exit /*@ HELP */ +rexx comment /* REXXSKEL back-end removed for space */ diff --git a/test/expected_dir/rexx1.rex/rexx/blanks b/test/expected_dir/rexx1.rex/rexx/blanks deleted file mode 100644 index 72f523f..0000000 --- a/test/expected_dir/rexx1.rex/rexx/blanks +++ /dev/null @@ -1 +0,0 @@ -39 \ No newline at end of file diff --git a/test/expected_dir/rexx1.rex/rexx/code b/test/expected_dir/rexx1.rex/rexx/code deleted file mode 100644 index 1cc1366..0000000 --- a/test/expected_dir/rexx1.rex/rexx/code +++ /dev/null @@ -1,231 +0,0 @@ -*/ arg argline -address TSO /* REXXSKEL ver.19991109 */ -arg parms "((" opts -signal on syntax -signal on novalue -call TOOLKIT_INIT /* conventional start-up -*/ -rc = Trace(tv) -info = parms /* to enable parsing */ -if \sw.inispf then do -arg line -line = line "(( RESTARTED" /* tell the next invocation */ -"ISPSTART CMD("exec_name line")" /* Invoke ISPF if nec. */ -exit /* ...and restart it */ -end -call A_INIT /* -*/ -"NEWSTACK" -if \sw.0error_found then, -call C_TABLE_OPS /* -*/ -if \sw.0error_found then, -call D_PUMP_TBL /* -*/ -"DELSTACK" -if sw.restarted then do -rc = OutTrap("ll.") -exit 4 -end -exit /*@ FLTTBL */ -A_INIT: /*@ */ -if branch then call BRANCH -address TSO -call AA_KEYWDS /* -*/ -parse var info $tn$ . /* table-name required */ -if $tn$ = "" then do -helpmsg = "Tablename is required." -call HELP -end -parse value outdsn "FLATTBLS."$tn$ with, -outdsn . -xefef = "efef"x -if tblds = "" then do -call AB_FIND_LIBRARY /* -*/ -if tblds = "" then do -helpmsg = "Table" $tn$ "was not found in ISPTLIB. Please", -"restart specifying a library name as shown below." -call HELP /* ...and don't come back */ -end -end -else, -if Left(tblds,1) = "'" then tblds = Strip(tblds,,"'") -else tblds = Userid()"."tblds -return /*@ A_INIT */ -AA_KEYWDS: /*@ */ -if branch then call BRANCH -address TSO -tblds = KEYWD("IN") -outdsn = KEYWD("OUTPUT") -sortseq = KEYWD("SORT") -sw.0purge = SWITCH("DELETEBEHIND") -parse value KEYWD("ADD") "0" with bytes_to_add . -return /*@ AA_KEYWDS */ -AB_FIND_LIBRARY: /*@ */ -if branch then call BRANCH -address TSO -"NEWSTACK" -"LA ISPTLIB ((STACK LINE" -pull tliblist -"DELSTACK" -do Words(tliblist) /* each library */ -parse var tliblist tblds tliblist -if Sysdsn("'"tblds"("$tn$")'") = "OK" then return -end /* tliblist */ -tblds = "" -return /*@ AB_FIND_LIBRARY */ -C_TABLE_OPS: /*@ */ -if branch then call BRANCH -address ISPEXEC -call CA_OPEN_TBL /* -*/ -call CS_SPIN_TBL /* -*/ -call CZ_DROP_TBL /* -*/ -return /*@ C_TABLE_OPS */ -CA_OPEN_TBL: /*@ */ -if branch then call BRANCH -address ISPEXEC -"LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" -"TBSTATS" $tn$ "STATUS1(s1) STATUS2(s2) ROWCURR(rowct)" -if s1 > 1 then do -say "Table" $tn$ "not available." -sw.0error_found = "1"; return -end; else, -if s2 = 1 then, /* not open */ -"TBOPEN " $tn$ "NOWRITE" -else "TBTOP" $tn$ -"LIBDEF ISPTLIB" -if sw.0error_found then return -"TBQUERY" $tn$ "KEYS(keylist)", -"NAMES(nmlist)" -parse var keylist "(" keylist ")" -parse var nmlist "(" nmlist ")" -namelist = keylist nmlist -if sortseq <> "" then "TBSORT" $tn$ "FIELDS("sortseq")" -return /*@ CA_OPEN_TBL */ -CS_SPIN_TBL: Procedure expose, /*@ hide everything */ -expose (tk_globalvars), /* except these */ -$tn$ namelist xefef tblds rows keylist nmlist maxlen -cs_tv = Trace() -if branch then call BRANCH -address ISPEXEC -maxlen = 0 /* maximum line length */ -do forever -"TBSKIP" $tn$ "SAVENAME(xvars)" -if rc > 0 then leave /* we're done... */ -line = "" /* set empty */ -do cx = 1 to Words(namelist) -thiswd = Word(namelist,cx) -line = line thiswd xefef Value(thiswd) xefef -end /* cx */ -rc = Trace("O"); rc = Trace(cs_tv) -parse var xvars "(" xvars ")" -line = line "XVARS" xefef xvars xefef -do cx = 1 to Words(xvars) -thiswd = Word(xvars,cx) -line = line thiswd xefef Value(thiswd) xefef -end /* cx */ -rc = Trace("O"); rc = Trace(cs_tv) -maxlen = Max(maxlen,Length(line)) -queue line -end /* forever */ -lines_in_stack = queued() -line = "Contents of" $tn$ "in" tblds, -"("lines_in_stack" rows) KEYS("keylist") NAMES("nmlist")." -push line /* make it the first line */ -maxlen = Max(maxlen,Length(line)) -if monitor then say "Maximum line length is" maxlen -return /*@ CS_SPIN_TBL */ -CZ_DROP_TBL: /*@ */ -if branch then call BRANCH -address ISPEXEC -if s2 = 1 then, /* table was not open at start*/ -"TBEND" $tn$ -return /*@ CZ_DROP_TBL */ -D_PUMP_TBL: /*@ */ -if branch then call BRANCH -address TSO -if monitor then say, -"Writing text." -maxlen = maxlen + 4 + bytes_to_add /* set LRECL */ -vbmax.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", -"RECFM(V B) LRECL("maxlen") BLKSIZE(0)" -vbmax.1 = "SHR" /* if it already exists... */ -tempstat = Sysdsn(outdsn) = "OK" /* 1=exists, 0=missing */ -"ALLOC FI($TMP) DA("outdsn") REU" vbmax.tempstat -rcx = rc -"EXECIO" queued() "DISKW $TMP (FINIS" -rcx = max(rcx,rc) -"FREE FI($TMP)" -if rcx = 0 & sw.0purge then do -address ISPEXEC -"LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" -"TBERASE" $tn$ -if rc = 0 then say $tn$ "was deleted" -"LIBDEF ISPTLIB" -end -return /*@ D_PUMP_TBL */ -LOCAL_PREINIT: /*@ customize opts */ -if branch then call BRANCH -address TSO -return /*@ LOCAL_PREINIT */ -HELP: /*@ */ -address TSO;"CLEAR" -if helpmsg <> "" then do ; say helpmsg; say ""; end -ex_nam = Left(exec_name,8) /* predictable size */ -say " "ex_nam" produces a flattened version of any ISPF table " -say " into a VB-form dataset of minimum necessary LRECL." -say " " -say " The field contents are written in KEYPHRS format " -say " (var .. varval ..) " -say " key-fields first, followed by name-fields, followed by the " -say " names of any extension variables key-phrased by 'XVARS', " -say " followed by the extension variables themselves in KEYPHRS " -say " format. " -say " " -say " The first record on the file identifies the table name, the " -say " source library, the number of rows processed, and the key- and " -say " name-fields. " -say " " -say " more.... " -pull -"CLEAR" -say " Syntax: "ex_nam" (Required)" -say " " -say " (Defaults)" -say " " -say " (Defaults)" -say " " -say " identifies the table to be dumped. " -say " " -say " identifies the ISPF Table library which holds ." -say " If is not specified, ISPTLIB will be " -say " searched to find the correct dataset. " -say " " -say " (default: FLATTBLS.) names the output file. " -say " will be created if it does not exist. " -say " " -say " causes the table to be sorted as indicated before " -say " being dumped. " -say " " -say " (default=0) causes the LRECL of the output dataset " -say " to be extended to enable updating. " -pull -"CLEAR" -say " Debugging tools provided include: " -say " " -say " MONITOR: displays key information throughout processing. " -say " Displays most paragraph names upon entry. " -say " " -say " NOUPDT: by-pass all update logic. " -say " " -say " BRANCH: show all paragraph entries. " -say " " -say " TRACE tv: will use value following TRACE to place the " -say " execution in REXX TRACE Mode. " -say " " -say " " -say " Debugging tools can be accessed in the following manner: " -say " " -say " TSO "ex_nam" parameters (( debug-options " -say " " -say " For example: " -say " " -say " TSO "ex_nam" vt2231 add 17 (( MONITOR TRACE ?R " -address ISPEXEC "CONTROL DISPLAY REFRESH" -exit /*@ HELP */ diff --git a/test/expected_dir/rexx1.rex/rexx/comment b/test/expected_dir/rexx1.rex/rexx/comment deleted file mode 100644 index 7934af6..0000000 --- a/test/expected_dir/rexx1.rex/rexx/comment +++ /dev/null @@ -1,41 +0,0 @@ -/* REXX FLTTBL Cloned from DUMPTBL 960619 to produce a flat -version (up to 32K characters wide) of any ISPF -table. -Written by Frank Clarke, Oldsmar, FL -Impact Analysis -. SYSPROC LA -. SYSPROC TRAPOUT -Modification History -19960918 fxc added some error-checking -19970115 fxc upgrade REXXSKEL from v.960606 to v.970113; add -RESTARTability; -19991231 fxc upgrade REXXSKEL from v.970113 to v.19991109; -RXSKLY2K; DECOMM; LRECL reduced from 32K to "min -needed"; -/* -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* - was not specified. Locate the table in ISPTLIB. -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* -. Given: contains all the defined names for this table. -The table has been TOPped. -. ----------------------------------------------------------------- */ -/* add blocks of "var .. varvalue .." */ -/* add a block of "XVARS .. xvarlist .." */ -/* add blocks of "xvar .. xvarvalue .." */ -/* -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* -. ----------------------------------------------------------------- */ -/* REXXSKEL back-end removed for space */ diff --git a/test/expected_dir/rhtml1.rhtml b/test/expected_dir/rhtml1.rhtml new file mode 100644 index 0000000..53d1d03 --- /dev/null +++ b/test/expected_dir/rhtml1.rhtml @@ -0,0 +1,25 @@ +html code +html code +html code Ajax table manipulation attempt +ruby code <%= stylesheet_link_tag "style" %> +ruby code <%= javascript_include_tag :defaults %> +html code +html code +html blank +html code
+ruby code <%= @content_for_layout %> +html code
+html blank +ruby code <%= ruby code %>
+html comment +ruby code <%- multi +ruby code lines of code +ruby comment # even inline comments! +ruby code "damn" # that's sweet +html code %> +ruby code
<%= ruby_code %>
+html code +html code diff --git a/test/expected_dir/rhtml1.rhtml/html/blanks b/test/expected_dir/rhtml1.rhtml/html/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/rhtml1.rhtml/html/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/rhtml1.rhtml/html/code b/test/expected_dir/rhtml1.rhtml/html/code deleted file mode 100644 index 40165c5..0000000 --- a/test/expected_dir/rhtml1.rhtml/html/code +++ /dev/null @@ -1,10 +0,0 @@ - - -Ajax table manipulation attempt - - -
-
-%> - - diff --git a/test/expected_dir/rhtml1.rhtml/html/comment b/test/expected_dir/rhtml1.rhtml/html/comment deleted file mode 100644 index eaabbad..0000000 --- a/test/expected_dir/rhtml1.rhtml/html/comment +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/expected_dir/rhtml1.rhtml/ruby/code b/test/expected_dir/rhtml1.rhtml/ruby/code deleted file mode 100644 index 32b01ec..0000000 --- a/test/expected_dir/rhtml1.rhtml/ruby/code +++ /dev/null @@ -1,9 +0,0 @@ -<%= stylesheet_link_tag "style" %> -<%= javascript_include_tag :defaults %> -<%= @content_for_layout %> -<%= ruby code %>
-<% tricky code %> -<%- multi -lines of code -"damn" # that's sweet -
<%= ruby_code %>
diff --git a/test/expected_dir/rhtml1.rhtml/ruby/comment b/test/expected_dir/rhtml1.rhtml/ruby/comment deleted file mode 100644 index 7529c9d..0000000 --- a/test/expected_dir/rhtml1.rhtml/ruby/comment +++ /dev/null @@ -1 +0,0 @@ -# even inline comments! diff --git a/test/expected_dir/ruby1.rb b/test/expected_dir/ruby1.rb new file mode 100644 index 0000000..25b7f9c --- /dev/null +++ b/test/expected_dir/ruby1.rb @@ -0,0 +1,22 @@ +ruby code require 'foo' +ruby blank +ruby comment #comment +ruby comment #comment +ruby comment #comment with "string" +ruby blank +ruby code module Foo +ruby code class Bar #comment +ruby code def foo +ruby code "double_quoted string" +ruby code "embedded double_quote \"" +ruby code more_code = true +ruby code 'single_quoted string' +ruby code 'embedded single_quote\'' +ruby code more_code = true +ruby code "multiline dquote +ruby code more quote +ruby code # not a comment +ruby code " +ruby code end +ruby code end +ruby code end diff --git a/test/expected_dir/ruby1.rb/ruby/blanks b/test/expected_dir/ruby1.rb/ruby/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/ruby1.rb/ruby/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/ruby1.rb/ruby/code b/test/expected_dir/ruby1.rb/ruby/code deleted file mode 100644 index fbbbd4d..0000000 --- a/test/expected_dir/ruby1.rb/ruby/code +++ /dev/null @@ -1,17 +0,0 @@ -require 'foo' -module Foo -class Bar #comment -def foo -"double_quoted string" -"embedded double_quote \"" -more_code = true -'single_quoted string' -'embedded single_quote\'' -more_code = true -"multiline dquote -more quote -# not a comment -" -end -end -end diff --git a/test/expected_dir/ruby1.rb/ruby/comment b/test/expected_dir/ruby1.rb/ruby/comment deleted file mode 100644 index 5e30320..0000000 --- a/test/expected_dir/ruby1.rb/ruby/comment +++ /dev/null @@ -1,3 +0,0 @@ -#comment -#comment -#comment with "string" diff --git a/test/expected_dir/rust.rs b/test/expected_dir/rust.rs new file mode 100644 index 0000000..1c6b0e0 --- /dev/null +++ b/test/expected_dir/rust.rs @@ -0,0 +1,16 @@ +rust comment /* +rust comment * This is the example given by www.rust-lang.org +rust comment */ +rust comment // Line comments work too +rust code fn main() { +rust code let nums = [1, 2]; +rust code let noms = ["Tim", "Eston", "Aaron", "Ben"]; +rust blank +rust code let mut odds = nums.iter().map(|&x| x * 2 - 1); +rust blank +rust code for num in odds { +rust code do spawn { +rust code println!("{:s} says hello from a lightweight thread!", noms[num]); +rust code } +rust code } +rust code } diff --git a/test/expected_dir/sample.i3 b/test/expected_dir/sample.i3 new file mode 100644 index 0000000..43b051b --- /dev/null +++ b/test/expected_dir/sample.i3 @@ -0,0 +1,12 @@ +modula3 code (* Modula-3 *) INTERFACE M3Sample; (* file extension ".i3" *) +modula3 blank +modula3 comment (* This is a comment *) +modula3 blank +modula3 comment (* This is a comment ... +modula3 comment ... spanning more than one line *) +modula3 blank +modula3 code CONST +modula3 code sqString = 'this is a string within "a string" ...\n'; +modula3 code dqString = "this is a string within 'a string' ...\n"; +modula3 blank +modula3 code END M3Sample. diff --git a/test/expected_dir/sample.m3 b/test/expected_dir/sample.m3 new file mode 100644 index 0000000..f525d0b --- /dev/null +++ b/test/expected_dir/sample.m3 @@ -0,0 +1,12 @@ +modula3 code (* Modula-3 *) MODULE M3Sample; (* file extension ".m3" *) +modula3 blank +modula3 comment (* This is a comment *) +modula3 blank +modula3 comment (* This is a comment ... +modula3 comment ... spanning more than one line *) +modula3 blank +modula3 code CONST +modula3 code sqString = 'this is a string within "a string" ...\n'; +modula3 code dqString = "this is a string within 'a string' ...\n"; +modula3 blank +modula3 code END M3Sample. diff --git a/test/expected_dir/sample.mod b/test/expected_dir/sample.mod new file mode 100644 index 0000000..cd40648 --- /dev/null +++ b/test/expected_dir/sample.mod @@ -0,0 +1,12 @@ +modula2 code MODULE Sample; (* in Modula-2 *) +modula2 blank +modula2 comment (* This is a comment *) +modula2 blank +modula2 comment (* This is a comment ... +modula2 comment ... spanning more than one line *) +modula2 blank +modula2 code CONST +modula2 code sqString = 'this is a string within "a string" ...'; +modula2 code dqString = "this is a string within 'a string' ..."; +modula2 blank +modula2 code END Sample. diff --git a/test/expected_dir/sample.ob2 b/test/expected_dir/sample.ob2 new file mode 100644 index 0000000..4561fee --- /dev/null +++ b/test/expected_dir/sample.ob2 @@ -0,0 +1,12 @@ +oberon code (* Oberon-2 *) MODULE OberonSample; (* file extension ".ob2" *) +oberon blank +oberon comment (* This is a comment *) +oberon blank +oberon comment (* This is a comment ... +oberon comment ... spanning more than one line *) +oberon blank +oberon code CONST +oberon code sqString* = 'this is a string within "a string" ...'; +oberon code dqString* = "this is a string within 'a string' ..."; +oberon blank +oberon code END OberonSample. diff --git a/test/expected_dir/sample.obn b/test/expected_dir/sample.obn new file mode 100644 index 0000000..faa5ca7 --- /dev/null +++ b/test/expected_dir/sample.obn @@ -0,0 +1,12 @@ +oberon code (* Oberon *) MODULE OberonSample; (* file extension ".obn" *) +oberon blank +oberon comment (* This is a comment *) +oberon blank +oberon comment (* This is a comment ... +oberon comment ... spanning more than one line *) +oberon blank +oberon code CONST +oberon code sqString* = 'this is a string within "a string" ...'; +oberon code dqString* = "this is a string within 'a string' ..."; +oberon blank +oberon code END OberonSample. diff --git a/test/expected_dir/sampleDef.def b/test/expected_dir/sampleDef.def new file mode 100644 index 0000000..11842b4 --- /dev/null +++ b/test/expected_dir/sampleDef.def @@ -0,0 +1,12 @@ +modula2 code DEFINITION MODULE Sample; (* in Modula-2 *) +modula2 blank +modula2 comment (* This is a comment *) +modula2 blank +modula2 comment (* This is a comment ... +modula2 comment ... spanning more than one line *) +modula2 blank +modula2 code CONST +modula2 code sqString = 'this is a string within "a string" ...'; +modula2 code dqString = "this is a string within 'a string' ..."; +modula2 blank +modula2 code END Sample. diff --git a/test/expected_dir/sampleImp.mod b/test/expected_dir/sampleImp.mod new file mode 100644 index 0000000..04f19ce --- /dev/null +++ b/test/expected_dir/sampleImp.mod @@ -0,0 +1,12 @@ +modula2 code IMPLEMENTATION MODULE Sample; (* in Modula-2 *) +modula2 blank +modula2 comment (* This is a comment *) +modula2 blank +modula2 comment (* This is a comment ... +modula2 comment ... spanning more than one line *) +modula2 blank +modula2 code CONST +modula2 code sqString = 'this is a string within "a string" ...'; +modula2 code dqString = "this is a string within 'a string' ..."; +modula2 blank +modula2 code END Sample. diff --git a/test/expected_dir/scala1.scala b/test/expected_dir/scala1.scala new file mode 100644 index 0000000..fa67832 --- /dev/null +++ b/test/expected_dir/scala1.scala @@ -0,0 +1,63 @@ +scala code import scala.actors.Actor +scala blank +scala code case object Ping +scala code case object Pong +scala code case object Stop +scala blank +scala comment /** +scala comment * Ping class +scala comment */ +scala code class Ping(count: int, pong: Actor) extends Actor { +scala code def act() { +scala code var pingsLeft = count - 1 +scala code pong ! Ping +scala code while (true) { +scala code receive { +scala code case Pong => +scala code if (pingsLeft % 1000 == 0) +scala code Console.println("Ping: pong") +scala code if (pingsLeft > 0) { +scala code pong ! Ping +scala code pingsLeft -= 1 +scala code } else { +scala code Console.println("Ping: stop") +scala code pong ! Stop +scala code exit() +scala code } +scala code } +scala code } +scala code } +scala code } +scala blank +scala comment /** +scala comment * Pong class +scala comment */ +scala code class Pong extends Actor { +scala code def act() { +scala code var pongCount = 0 +scala code while (true) { +scala code receive { +scala comment //pong back the ping +scala code case Ping => +scala code if (pongCount % 1000 == 0) +scala code Console.println("Pong: ping "+pongCount) +scala code sender ! Pong +scala code pongCount = pongCount + 1 +scala comment //stop ping ponging +scala code case Stop => +scala code Console.println("Pong: stop") +scala code exit() +scala code } +scala code } +scala code } +scala code } +scala blank +scala comment /* +scala comment * And this is the main application, playing a game of ping pong +scala comment */ +scala code object PingPong extends Application { +scala code val pong = new Pong +scala code val ping = new Ping(100000, pong) +scala code ping.start +scala code pong.start +scala code } diff --git a/test/expected_dir/scala1.scala/scala/blanks b/test/expected_dir/scala1.scala/scala/blanks deleted file mode 100644 index bf0d87a..0000000 --- a/test/expected_dir/scala1.scala/scala/blanks +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/test/expected_dir/scala1.scala/scala/code b/test/expected_dir/scala1.scala/scala/code deleted file mode 100644 index 3392f0c..0000000 --- a/test/expected_dir/scala1.scala/scala/code +++ /dev/null @@ -1,48 +0,0 @@ -import scala.actors.Actor -case object Ping -case object Pong -case object Stop -class Ping(count: int, pong: Actor) extends Actor { -def act() { -var pingsLeft = count - 1 -pong ! Ping -while (true) { -receive { -case Pong => -if (pingsLeft % 1000 == 0) -Console.println("Ping: pong") -if (pingsLeft > 0) { -pong ! Ping -pingsLeft -= 1 -} else { -Console.println("Ping: stop") -pong ! Stop -exit() -} -} -} -} -} -class Pong extends Actor { -def act() { -var pongCount = 0 -while (true) { -receive { -case Ping => -if (pongCount % 1000 == 0) -Console.println("Pong: ping "+pongCount) -sender ! Pong -pongCount = pongCount + 1 -case Stop => -Console.println("Pong: stop") -exit() -} -} -} -} -object PingPong extends Application { -val pong = new Pong -val ping = new Ping(100000, pong) -ping.start -pong.start -} diff --git a/test/expected_dir/scala1.scala/scala/comment b/test/expected_dir/scala1.scala/scala/comment deleted file mode 100644 index 3aaaee9..0000000 --- a/test/expected_dir/scala1.scala/scala/comment +++ /dev/null @@ -1,11 +0,0 @@ -/** -* Ping class -*/ -/** -* Pong class -*/ -//pong back the ping -//stop ping ponging -/* -* And this is the main application, playing a game of ping pong -*/ diff --git a/test/expected_dir/schema.xsd b/test/expected_dir/schema.xsd new file mode 100644 index 0000000..59df2e6 --- /dev/null +++ b/test/expected_dir/schema.xsd @@ -0,0 +1,68 @@ +xmlschema code +xmlschema comment +xmlschema code +xmlschema code +xmlschema code +xmlschema code 0836217462 +xmlschema code +xmlschema code +xmlschema code Being a Dog Is a Full-Time Job +xmlschema code +xmlschema code +xmlschema code +xmlschema code Charles M Schulz +xmlschema code +xmlschema code +xmlschema code 1922-11-26 +xmlschema code +xmlschema code +xmlschema code 2000-02-12 +xmlschema code +xmlschema code +xmlschema code +xmlschema code +xmlschema code Peppermint Patty +xmlschema code +xmlschema code +xmlschema code 1966-08-22 +xmlschema code +xmlschema code +xmlschema code bold, brash and tomboyish +xmlschema code +xmlschema code +xmlschema code +xmlschema code +xmlschema code Snoopy +xmlschema code +xmlschema code +xmlschema code 1950-10-04 +xmlschema code +xmlschema code +xmlschema code extroverted beagle +xmlschema code +xmlschema code +xmlschema code +xmlschema code +xmlschema code Schroeder +xmlschema code +xmlschema code +xmlschema code 1951-05-30 +xmlschema code +xmlschema code +xmlschema code brought classical music to the Peanuts strip +xmlschema code +xmlschema code +xmlschema code +xmlschema code +xmlschema code Lucy +xmlschema code +xmlschema code +xmlschema code 1952-03-03 +xmlschema code +xmlschema code +xmlschema code bossy, crabby and selfish +xmlschema code +xmlschema code +xmlschema code +xmlschema code diff --git a/test/expected_dir/schema.xsd/xmlschema/blanks b/test/expected_dir/schema.xsd/xmlschema/blanks deleted file mode 100644 index c227083..0000000 --- a/test/expected_dir/schema.xsd/xmlschema/blanks +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/test/expected_dir/schema.xsd/xmlschema/code b/test/expected_dir/schema.xsd/xmlschema/code deleted file mode 100644 index aed5bad..0000000 --- a/test/expected_dir/schema.xsd/xmlschema/code +++ /dev/null @@ -1,66 +0,0 @@ - - - - -0836217462 - - -Being a Dog Is a Full-Time Job - - - -Charles M Schulz - - -1922-11-26 - - -2000-02-12 - - - - -Peppermint Patty - - -1966-08-22 - - -bold, brash and tomboyish - - - - -Snoopy - - -1950-10-04 - - -extroverted beagle - - - - -Schroeder - - -1951-05-30 - - -brought classical music to the Peanuts strip - - - - -Lucy - - -1952-03-03 - - -bossy, crabby and selfish - - - - diff --git a/test/expected_dir/schema.xsd/xmlschema/comment b/test/expected_dir/schema.xsd/xmlschema/comment deleted file mode 100644 index 578e50a..0000000 --- a/test/expected_dir/schema.xsd/xmlschema/comment +++ /dev/null @@ -1,2 +0,0 @@ - diff --git a/test/expected_dir/scheme.scm b/test/expected_dir/scheme.scm new file mode 100644 index 0000000..5db5fdc --- /dev/null +++ b/test/expected_dir/scheme.scm @@ -0,0 +1,32 @@ +scheme code (+ 1 (/ 1 0) 3) +scheme comment ; => A divide by zero error is raised +scheme blank +scheme code (with-failure-continuation +scheme code (lambda (error-record error-k) +scheme code 'error) +scheme code (lambda () (+ 1 (/ 1 0) 3))) +scheme comment ; => The symbol 'error +scheme blank +scheme code (with-failure-continuation +scheme code (lambda (error-record error-k) +scheme code (error-k 2)) +scheme code (lambda () (+ 1 (/ 1 0) 3))) +scheme comment ; => 6 +scheme blank +scheme code (with-failure-continuation +scheme code (lambda (error-record error-k) +scheme code (throw error-record error-k)) +scheme code (lambda () (+ 1 (/ 1 0) 3))) +scheme comment ; => A divide by zero error is raised +scheme blank +scheme code (with-failure-continuation +scheme code (lambda (error-record error-k) +scheme code (throw (make-error '/ "could not perform the division.") error-k)) +scheme code (lambda () (+ 1 (/ 1 0) 3))) +scheme comment ; => An error is raised: Error in /: could not perform the division. +scheme blank +scheme code (with-failure-continuation +scheme code (lambda (error-record error-k) +scheme code (error 'example-function "could not evaluate the expression.")) +scheme code (lambda () (+ 1 (/ 1 0) 3))) +scheme comment ; => An error is raised: Error in example-function: could not evaluate the expression. diff --git a/test/expected_dir/scheme.scm/scheme/blanks b/test/expected_dir/scheme.scm/scheme/blanks deleted file mode 100644 index 7813681..0000000 --- a/test/expected_dir/scheme.scm/scheme/blanks +++ /dev/null @@ -1 +0,0 @@ -5 \ No newline at end of file diff --git a/test/expected_dir/scheme.scm/scheme/code b/test/expected_dir/scheme.scm/scheme/code deleted file mode 100644 index 21821bb..0000000 --- a/test/expected_dir/scheme.scm/scheme/code +++ /dev/null @@ -1,21 +0,0 @@ -(+ 1 (/ 1 0) 3) -(with-failure-continuation -(lambda (error-record error-k) -'error) -(lambda () (+ 1 (/ 1 0) 3))) -(with-failure-continuation -(lambda (error-record error-k) -(error-k 2)) -(lambda () (+ 1 (/ 1 0) 3))) -(with-failure-continuation -(lambda (error-record error-k) -(throw error-record error-k)) -(lambda () (+ 1 (/ 1 0) 3))) -(with-failure-continuation -(lambda (error-record error-k) -(throw (make-error '/ "could not perform the division.") error-k)) -(lambda () (+ 1 (/ 1 0) 3))) -(with-failure-continuation -(lambda (error-record error-k) -(error 'example-function "could not evaluate the expression.")) -(lambda () (+ 1 (/ 1 0) 3))) diff --git a/test/expected_dir/scheme.scm/scheme/comment b/test/expected_dir/scheme.scm/scheme/comment deleted file mode 100644 index 9ca013b..0000000 --- a/test/expected_dir/scheme.scm/scheme/comment +++ /dev/null @@ -1,6 +0,0 @@ -; => A divide by zero error is raised -; => The symbol 'error -; => 6 -; => A divide by zero error is raised -; => An error is raised: Error in /: could not perform the division. -; => An error is raised: Error in example-function: could not evaluate the expression. diff --git a/test/expected_dir/scilab.sci b/test/expected_dir/scilab.sci new file mode 100644 index 0000000..16fb951 --- /dev/null +++ b/test/expected_dir/scilab.sci @@ -0,0 +1,35 @@ +scilab comment // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +scilab comment // Copyright (C) INRIA - Serge STEER +scilab comment // +scilab comment // This file must be used under the terms of the CeCILL. +scilab comment // This source file is licensed as described in the file COPYING, which +scilab comment // you should have received as part of this distribution. The terms +scilab comment // are also available at +scilab comment // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +scilab blank +scilab code function I=sub2ind(dims,varargin) +scilab comment //sub2ind is used to determine the equivalent single index +scilab comment //corresponding to a given set of subscript values. +scilab blank +scilab comment //I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the +scilab comment //row, column, ... subscripts in the arrays i1,i2,.. for an matrix of +scilab comment //size dims. +scilab blank +scilab comment //I = sub2ind(dims,Mi) returns the linear index +scilab comment //equivalent to the n subscripts in the columns of the matrix Mi for a matrix +scilab comment //of size dims. +scilab blank +scilab code d=[1;cumprod(matrix(dims(1:$-1),-1,1))] +scilab code for i=1:size(varargin) +scilab code if varargin(i)==[] then I=[],return,end +scilab code end +scilab blank +scilab code if size(varargin)==1 then //subindices are the columns of the argument +scilab code I=(varargin(1)-1)*d+1 +scilab code else //subindices are given as separated arguments +scilab code I=1 +scilab code for i=1:size(varargin) +scilab code I=I+(varargin(i)-1)*d(i) +scilab code end +scilab code end +scilab code endfunction diff --git a/test/expected_dir/sh1.sh b/test/expected_dir/sh1.sh new file mode 100644 index 0000000..665557c --- /dev/null +++ b/test/expected_dir/sh1.sh @@ -0,0 +1,5 @@ +shell comment #!/bin/sh +shell blank +shell code ls -la +shell comment # comment +shell code echo hello #comment diff --git a/test/expected_dir/sh1.sh/shell/blanks b/test/expected_dir/sh1.sh/shell/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/sh1.sh/shell/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/sh1.sh/shell/code b/test/expected_dir/sh1.sh/shell/code deleted file mode 100644 index 6c62c92..0000000 --- a/test/expected_dir/sh1.sh/shell/code +++ /dev/null @@ -1,2 +0,0 @@ -ls -la -echo hello #comment diff --git a/test/expected_dir/sh1.sh/shell/comment b/test/expected_dir/sh1.sh/shell/comment deleted file mode 100644 index 904cf48..0000000 --- a/test/expected_dir/sh1.sh/shell/comment +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -# comment diff --git a/test/expected_dir/sh2.sh b/test/expected_dir/sh2.sh new file mode 100644 index 0000000..af6a968 --- /dev/null +++ b/test/expected_dir/sh2.sh @@ -0,0 +1,5 @@ +shell code var="\ +shell code Some string" +shell blank +shell comment # Now a comment +shell code var="some new string" diff --git a/test/expected_dir/smalltalk1.st b/test/expected_dir/smalltalk1.st new file mode 100644 index 0000000..07859e5 --- /dev/null +++ b/test/expected_dir/smalltalk1.st @@ -0,0 +1,19 @@ +smalltalk comment "====================================================================== +smalltalk comment | +smalltalk comment | Benchmark for streams +smalltalk comment | +smalltalk comment | +smalltalk comment ======================================================================" +smalltalk blank +smalltalk blank +smalltalk code Eval [ +smalltalk code n := Smalltalk arguments isEmpty +smalltalk code ifTrue: [ 10000 ] +smalltalk code ifFalse: [ 1 max: Smalltalk arguments first asInteger ]. +smalltalk blank +smalltalk code hello := String new writeStream. +smalltalk code n timesRepeat: [ hello nextPutAll: 'hello +smalltalk code \' ]. "this is a comment +smalltalk comment so this line is a comment too\" +smalltalk code hello position displayNl +smalltalk code "but the previous one, and this one too, are not!" ] diff --git a/test/expected_dir/smalltalk1.st/smalltalk/blanks b/test/expected_dir/smalltalk1.st/smalltalk/blanks deleted file mode 100644 index e440e5c..0000000 --- a/test/expected_dir/smalltalk1.st/smalltalk/blanks +++ /dev/null @@ -1 +0,0 @@ -3 \ No newline at end of file diff --git a/test/expected_dir/smalltalk1.st/smalltalk/code b/test/expected_dir/smalltalk1.st/smalltalk/code deleted file mode 100644 index d1ff6de..0000000 --- a/test/expected_dir/smalltalk1.st/smalltalk/code +++ /dev/null @@ -1,9 +0,0 @@ -Eval [ -n := Smalltalk arguments isEmpty -ifTrue: [ 10000 ] -ifFalse: [ 1 max: Smalltalk arguments first asInteger ]. -hello := String new writeStream. -n timesRepeat: [ hello nextPutAll: 'hello -\' ]. "this is a comment -hello position displayNl -"but the previous one, and this one too, are not!" ] diff --git a/test/expected_dir/smalltalk1.st/smalltalk/comment b/test/expected_dir/smalltalk1.st/smalltalk/comment deleted file mode 100644 index fb20617..0000000 --- a/test/expected_dir/smalltalk1.st/smalltalk/comment +++ /dev/null @@ -1,7 +0,0 @@ -"====================================================================== -| -| Benchmark for streams -| -| -======================================================================" -so this line is a comment too\" diff --git a/test/expected_dir/sql1.sql b/test/expected_dir/sql1.sql new file mode 100644 index 0000000..ed8ecd9 --- /dev/null +++ b/test/expected_dir/sql1.sql @@ -0,0 +1,31 @@ +sql comment // ----------------------------------------------------------------------- +sql comment // Filename: minvalue.sql +sql comment // Purpose: Select the Nth lowest value from a table +sql comment // Date: 18-Apr-2001 +sql comment // Author: Deepak Rai, SSE, Satyam Computer Services Ltd. India +sql comment // ----------------------------------------------------------------------- +sql blank +sql comment ## Comment with a hash symbol ## +sql code select level, min('col_name') from my_table +sql code where level = '&n' +sql code connect by prior ('col_name') < 'col_name') +sql code group by level; +sql blank +sql comment /* a block comment +sql comment -- finished here */ +sql blank +sql comment -- Example: +sql comment -- +sql comment -- Given a table called emp with the following columns: +sql comment -- id number +sql comment -- name varchar2(20) +sql comment -- sal number +sql comment -- +sql comment -- For the second lowest salary: +sql comment -- +sql comment -- select level, min(sal) from emp +sql comment -- where level=2 +sql comment -- connect by prior sal < sal +sql comment -- group by level +sql comment -- +sql blank diff --git a/test/expected_dir/sql1.sql/sql/blanks b/test/expected_dir/sql1.sql/sql/blanks deleted file mode 100644 index bf0d87a..0000000 --- a/test/expected_dir/sql1.sql/sql/blanks +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/test/expected_dir/sql1.sql/sql/code b/test/expected_dir/sql1.sql/sql/code deleted file mode 100644 index c59b1f8..0000000 --- a/test/expected_dir/sql1.sql/sql/code +++ /dev/null @@ -1,4 +0,0 @@ -select level, min('col_name') from my_table -where level = '&n' -connect by prior ('col_name') < 'col_name') -group by level; diff --git a/test/expected_dir/sql1.sql/sql/comment b/test/expected_dir/sql1.sql/sql/comment deleted file mode 100644 index 85fac5d..0000000 --- a/test/expected_dir/sql1.sql/sql/comment +++ /dev/null @@ -1,23 +0,0 @@ -// ----------------------------------------------------------------------- -// Filename: minvalue.sql -// Purpose: Select the Nth lowest value from a table -// Date: 18-Apr-2001 -// Author: Deepak Rai, SSE, Satyam Computer Services Ltd. India -// ----------------------------------------------------------------------- -## Comment with a hash symbol ## -/* a block comment --- finished here */ --- Example: --- --- Given a table called emp with the following columns: --- id number --- name varchar2(20) --- sal number --- --- For the second lowest salary: --- --- select level, min(sal) from emp --- where level=2 --- connect by prior sal < sal --- group by level --- diff --git a/test/expected_dir/stratego.str b/test/expected_dir/stratego.str new file mode 100644 index 0000000..483596d --- /dev/null +++ b/test/expected_dir/stratego.str @@ -0,0 +1,25 @@ +stratego comment /** +stratego comment * Sample code from Stratego XT Manual +stratego comment */ +stratego blank +stratego code rules +stratego code InlineF : +stratego code |[ let f(xs) = e in e'[f(es)] ]| -> +stratego code |[ let f(xs) = e in e'[e[es/xs]] ]| +stratego blank +stratego code InlineV : +stratego code |[ let x = e in e'[x] ]| -> |[ let x = e in e'[e] ]| +stratego blank +stratego code Dead : +stratego code |[ let x = e in e' ]| -> |[ e' ]| +stratego code where (x,e') +stratego blank +stratego code Extract(f,xs) : +stratego code |[ e ]| -> |[ let f(xs) = e in f(xs) ]| +stratego blank +stratego code Hoist : +stratego code |[ let x = e1 in let f(xs) = e2 in e3 ]| -> +stratego code |[ let f(xs) = e2 in let x = e1 in e3 ]| +stratego code where (x, e2) +stratego blank +stratego comment // better watch those apostrophes! diff --git a/test/expected_dir/stratego.str/stratego/blanks b/test/expected_dir/stratego.str/stratego/blanks deleted file mode 100644 index 62f9457..0000000 --- a/test/expected_dir/stratego.str/stratego/blanks +++ /dev/null @@ -1 +0,0 @@ -6 \ No newline at end of file diff --git a/test/expected_dir/stratego.str/stratego/code b/test/expected_dir/stratego.str/stratego/code deleted file mode 100644 index a87e954..0000000 --- a/test/expected_dir/stratego.str/stratego/code +++ /dev/null @@ -1,15 +0,0 @@ -rules -InlineF : -|[ let f(xs) = e in e'[f(es)] ]| -> -|[ let f(xs) = e in e'[e[es/xs]] ]| -InlineV : -|[ let x = e in e'[x] ]| -> |[ let x = e in e'[e] ]| -Dead : -|[ let x = e in e' ]| -> |[ e' ]| -where (x,e') -Extract(f,xs) : -|[ e ]| -> |[ let f(xs) = e in f(xs) ]| -Hoist : -|[ let x = e1 in let f(xs) = e2 in e3 ]| -> -|[ let f(xs) = e2 in let x = e1 in e3 ]| -where (x, e2) diff --git a/test/expected_dir/stratego.str/stratego/comment b/test/expected_dir/stratego.str/stratego/comment deleted file mode 100644 index 517a505..0000000 --- a/test/expected_dir/stratego.str/stratego/comment +++ /dev/null @@ -1,4 +0,0 @@ -/** -* Sample code from Stratego XT Manual -*/ -// better watch those apostrophes! diff --git a/test/expected_dir/structured_basic.b b/test/expected_dir/structured_basic.b new file mode 100644 index 0000000..00a1759 --- /dev/null +++ b/test/expected_dir/structured_basic.b @@ -0,0 +1,20 @@ +structured_basic code INPUT "What is your name: "; U$ +structured_basic code PRINT "Hello "; U$ +structured_basic comment REM Test +structured_basic code INPUT "How many stars do you want: "; N +structured_basic code S$ = "" +structured_basic code FOR I = 1 TO N +structured_basic code S$ = S$ + "*" +structured_basic code NEXT I +structured_basic code PRINT S$ +structured_basic blank +structured_basic comment REM +structured_basic code INPUT "Do you want more stars? "; A$ +structured_basic code IF LEN(A$) = 0 THEN GOTO 110 +structured_basic code A$ = LEFT$(A$, 1) +structured_basic code IF (A$ = "Y") OR (A$ = "y") THEN GOTO 40 +structured_basic code PRINT "Goodbye "; +structured_basic code FOR I = 1 TO 200 +structured_basic code PRINT U$; " "; +structured_basic code NEXT I +structured_basic code PRINT diff --git a/test/expected_dir/structured_basic.b/structured_basic/blanks b/test/expected_dir/structured_basic.b/structured_basic/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/structured_basic.b/structured_basic/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/structured_basic.b/structured_basic/code b/test/expected_dir/structured_basic.b/structured_basic/code deleted file mode 100644 index eb8a81a..0000000 --- a/test/expected_dir/structured_basic.b/structured_basic/code +++ /dev/null @@ -1,17 +0,0 @@ -INPUT "What is your name: "; U$ -PRINT "Hello "; U$ -INPUT "How many stars do you want: "; N -S$ = "" -FOR I = 1 TO N -S$ = S$ + "*" -NEXT I -PRINT S$ -INPUT "Do you want more stars? "; A$ -IF LEN(A$) = 0 THEN GOTO 110 -A$ = LEFT$(A$, 1) -IF (A$ = "Y") OR (A$ = "y") THEN GOTO 40 -PRINT "Goodbye "; -FOR I = 1 TO 200 -PRINT U$; " "; -NEXT I -PRINT diff --git a/test/expected_dir/structured_basic.b/structured_basic/comment b/test/expected_dir/structured_basic.b/structured_basic/comment deleted file mode 100644 index 8d21989..0000000 --- a/test/expected_dir/structured_basic.b/structured_basic/comment +++ /dev/null @@ -1,2 +0,0 @@ -REM Test -REM diff --git a/test/expected_dir/structured_basic.bas b/test/expected_dir/structured_basic.bas new file mode 100644 index 0000000..00a1759 --- /dev/null +++ b/test/expected_dir/structured_basic.bas @@ -0,0 +1,20 @@ +structured_basic code INPUT "What is your name: "; U$ +structured_basic code PRINT "Hello "; U$ +structured_basic comment REM Test +structured_basic code INPUT "How many stars do you want: "; N +structured_basic code S$ = "" +structured_basic code FOR I = 1 TO N +structured_basic code S$ = S$ + "*" +structured_basic code NEXT I +structured_basic code PRINT S$ +structured_basic blank +structured_basic comment REM +structured_basic code INPUT "Do you want more stars? "; A$ +structured_basic code IF LEN(A$) = 0 THEN GOTO 110 +structured_basic code A$ = LEFT$(A$, 1) +structured_basic code IF (A$ = "Y") OR (A$ = "y") THEN GOTO 40 +structured_basic code PRINT "Goodbye "; +structured_basic code FOR I = 1 TO 200 +structured_basic code PRINT U$; " "; +structured_basic code NEXT I +structured_basic code PRINT diff --git a/test/expected_dir/structured_basic.bas/structured_basic/blanks b/test/expected_dir/structured_basic.bas/structured_basic/blanks deleted file mode 100644 index 56a6051..0000000 --- a/test/expected_dir/structured_basic.bas/structured_basic/blanks +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/test/expected_dir/structured_basic.bas/structured_basic/code b/test/expected_dir/structured_basic.bas/structured_basic/code deleted file mode 100644 index eb8a81a..0000000 --- a/test/expected_dir/structured_basic.bas/structured_basic/code +++ /dev/null @@ -1,17 +0,0 @@ -INPUT "What is your name: "; U$ -PRINT "Hello "; U$ -INPUT "How many stars do you want: "; N -S$ = "" -FOR I = 1 TO N -S$ = S$ + "*" -NEXT I -PRINT S$ -INPUT "Do you want more stars? "; A$ -IF LEN(A$) = 0 THEN GOTO 110 -A$ = LEFT$(A$, 1) -IF (A$ = "Y") OR (A$ = "y") THEN GOTO 40 -PRINT "Goodbye "; -FOR I = 1 TO 200 -PRINT U$; " "; -NEXT I -PRINT diff --git a/test/expected_dir/structured_basic.bas/structured_basic/comment b/test/expected_dir/structured_basic.bas/structured_basic/comment deleted file mode 100644 index 8d21989..0000000 --- a/test/expected_dir/structured_basic.bas/structured_basic/comment +++ /dev/null @@ -1,2 +0,0 @@ -REM Test -REM diff --git a/test/expected_dir/tcl1.tcl b/test/expected_dir/tcl1.tcl new file mode 100644 index 0000000..eeccd1a --- /dev/null +++ b/test/expected_dir/tcl1.tcl @@ -0,0 +1,35 @@ +tcl comment #!/usr/local/bin/tclsh +tcl blank +tcl comment # Dos2Unix +tcl comment # Convert a file to Unix-style line endings +tcl comment # If the file is a directory, then recursively +tcl comment # convert all the files in the directory and below. +tcl comment # +tcl comment # Arguments +tcl comment # f The name of a file or directory. +tcl comment # +tcl comment # Side Effects: +tcl comment # Rewrites the file to have LF line-endings +tcl blank +tcl code proc Dos2Unix {f} { +tcl code puts $f +tcl code if {[file isdirectory $f]} { +tcl code foreach g [glob [file join $f *]] { +tcl code Dos2Unix $g +tcl code } +tcl code } else { +tcl code set in [open $f] +tcl code set out [open $f.new w] +tcl code fconfigure $out -translation lf +tcl code puts -nonewline $out [read $in] +tcl code close $out +tcl code close $in +tcl code file rename -force $f.new $f +tcl code } +tcl code } +tcl blank +tcl comment # Process each command-line argument +tcl blank +tcl code foreach f $argv { +tcl code Dos2Unix $f +tcl code } diff --git a/test/expected_dir/tcl1.tcl/tcl/blanks b/test/expected_dir/tcl1.tcl/tcl/blanks deleted file mode 100644 index bf0d87a..0000000 --- a/test/expected_dir/tcl1.tcl/tcl/blanks +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/test/expected_dir/tcl1.tcl/tcl/code b/test/expected_dir/tcl1.tcl/tcl/code deleted file mode 100644 index 51f4412..0000000 --- a/test/expected_dir/tcl1.tcl/tcl/code +++ /dev/null @@ -1,19 +0,0 @@ -proc Dos2Unix {f} { -puts $f -if {[file isdirectory $f]} { -foreach g [glob [file join $f *]] { -Dos2Unix $g -} -} else { -set in [open $f] -set out [open $f.new w] -fconfigure $out -translation lf -puts -nonewline $out [read $in] -close $out -close $in -file rename -force $f.new $f -} -} -foreach f $argv { -Dos2Unix $f -} diff --git a/test/expected_dir/tcl1.tcl/tcl/comment b/test/expected_dir/tcl1.tcl/tcl/comment deleted file mode 100644 index 0ed0d7b..0000000 --- a/test/expected_dir/tcl1.tcl/tcl/comment +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/local/bin/tclsh -# Dos2Unix -# Convert a file to Unix-style line endings -# If the file is a directory, then recursively -# convert all the files in the directory and below. -# -# Arguments -# f The name of a file or directory. -# -# Side Effects: -# Rewrites the file to have LF line-endings -# Process each command-line argument diff --git a/test/expected_dir/vala1.vala b/test/expected_dir/vala1.vala new file mode 100644 index 0000000..1453c0d --- /dev/null +++ b/test/expected_dir/vala1.vala @@ -0,0 +1,61 @@ +vala code using GLib; +vala blank +vala blank +vala blank +vala comment // Class which makes the event +vala code public class Game : Object { +vala comment // Note the use of the signal keyword +vala code public signal void score_change (int newScore, ref bool cancel); +vala blank +vala code int _score; +vala blank +vala comment // Score Property +vala code public int score { +vala code get { +vala code return _score; +vala code } +vala code set { +vala code if (_score != value) { +vala code bool cancel = false; +vala code score_change (value, ref cancel); +vala code if (! cancel) +vala code _score = value; +vala code } +vala code } +vala code } +vala code } +vala blank +vala comment // Class which handles the event +vala code public class Referee : Object +vala code { +vala code public Game game { get; construct; } +vala blank +vala code public Referee (construct Game game) { +vala code } +vala blank +vala code construct { +vala comment // Monitor when a score changes in the game +vala code game.score_change += game_score_change; +vala code } +vala blank +vala comment // Notice how this method signature matches the score_change signal's signature +vala code private void game_score_change (Game game, int new_score, ref bool cancel) { +vala code if (new_score < 100) +vala code stdout.printf ("Good Score\n"); +vala code else { +vala code cancel = true; +vala code stdout.printf ("No Score can be that high!\n"); +vala code } +vala code } +vala code } +vala blank +vala comment // Class to test it all +vala code public class GameTest : Object +vala code { +vala code public static void main () { +vala code var game = new Game (); +vala code var referee = new Referee (game); +vala code game.score = 70; +vala code game.score = 110; +vala code } +vala code } diff --git a/test/expected_dir/vala1.vala/vala/blanks b/test/expected_dir/vala1.vala/vala/blanks deleted file mode 100644 index 9a03714..0000000 --- a/test/expected_dir/vala1.vala/vala/blanks +++ /dev/null @@ -1 +0,0 @@ -10 \ No newline at end of file diff --git a/test/expected_dir/vala1.vala/vala/code b/test/expected_dir/vala1.vala/vala/code deleted file mode 100644 index 3d1283c..0000000 --- a/test/expected_dir/vala1.vala/vala/code +++ /dev/null @@ -1,44 +0,0 @@ -using GLib; -public class Game : Object { -public signal void score_change (int newScore, ref bool cancel); -int _score; -public int score { -get { -return _score; -} -set { -if (_score != value) { -bool cancel = false; -score_change (value, ref cancel); -if (! cancel) -_score = value; -} -} -} -} -public class Referee : Object -{ -public Game game { get; construct; } -public Referee (construct Game game) { -} -construct { -game.score_change += game_score_change; -} -private void game_score_change (Game game, int new_score, ref bool cancel) { -if (new_score < 100) -stdout.printf ("Good Score\n"); -else { -cancel = true; -stdout.printf ("No Score can be that high!\n"); -} -} -} -public class GameTest : Object -{ -public static void main () { -var game = new Game (); -var referee = new Referee (game); -game.score = 70; -game.score = 110; -} -} diff --git a/test/expected_dir/vala1.vala/vala/comment b/test/expected_dir/vala1.vala/vala/comment deleted file mode 100644 index 7f2c745..0000000 --- a/test/expected_dir/vala1.vala/vala/comment +++ /dev/null @@ -1,7 +0,0 @@ -// Class which makes the event -// Note the use of the signal keyword -// Score Property -// Class which handles the event -// Monitor when a score changes in the game -// Notice how this method signature matches the score_change signal's signature -// Class to test it all diff --git a/test/expected_dir/vb.aspx b/test/expected_dir/vb.aspx new file mode 100644 index 0000000..aed2fe2 --- /dev/null +++ b/test/expected_dir/vb.aspx @@ -0,0 +1,26 @@ +visualbasic code <%@ Page Language="VB" %> +html code +html code +html code +html code Basic ASP.NET Web Page +html code +html code +html code
+html code

Welcome to ASP.NET

+html code

Type your name and click the button.

+html code

+html code +html code +html code

+html code

+html code +html code

+html code
+html code +html code diff --git a/test/expected_dir/vb1.vb b/test/expected_dir/vb1.vb new file mode 100644 index 0000000..d450687 --- /dev/null +++ b/test/expected_dir/vb1.vb @@ -0,0 +1,16 @@ +visualbasic code class foo +visualbasic comment ' comment +visualbasic blank +visualbasic code require File.dirname(__FILE__) + '/../test_helper' +visualbasic code include Lingo +visualbasic blank +visualbasic code class ShellTest < LingoTest +visualbasic code def test_comment +visualbasic code p = Languages::Shell.parse(" #comment") +visualbasic code assert_equal({ 'shell' => { :comment => [" #comment"] } }, p.output_buffers) +visualbasic code end +visualbasic blank +visualbasic code def test_comprehensive +visualbasic code verify_parse("sh1.sh") +visualbasic code end +visualbasic code end diff --git a/test/expected_dir/vbs1.vbs b/test/expected_dir/vbs1.vbs new file mode 100644 index 0000000..639b463 --- /dev/null +++ b/test/expected_dir/vbs1.vbs @@ -0,0 +1,14 @@ +visualbasic blank +visualbasic code require File.dirname(__FILE__) + '/../test_helper' +visualbasic code include Lingo +visualbasic blank +visualbasic code class ShellTest < LingoTest +visualbasic code def test_comment +visualbasic code p = Languages::Shell.parse(" #comment") +visualbasic code assert_equal({ 'shell' => { :comment => [" #comment"] } }, p.output_buffers) +visualbasic code end +visualbasic blank +visualbasic code def test_comprehensive +visualbasic code verify_parse("sh1.sh") +visualbasic code end +visualbasic code end diff --git a/test/expected_dir/vhdl1.vhd b/test/expected_dir/vhdl1.vhd new file mode 100644 index 0000000..64fd306 --- /dev/null +++ b/test/expected_dir/vhdl1.vhd @@ -0,0 +1,92 @@ +vhdl comment ------------------------------------------------------------ +vhdl comment -- Combinational Logic Design +vhdl comment -- (ESD book figure 2.4) +vhdl comment -- by Weijun Zhang, 04/2001 +vhdl comment -- +vhdl comment -- A simple example of VHDL Structure Modeling +vhdl comment -- we might define two components in two separate files, +vhdl comment -- in main file, we use port map statement to instantiate +vhdl comment -- the mapping relationship between each components +vhdl comment -- and the entire circuit. +vhdl comment ------------------------------------------------------------ +vhdl blank +vhdl code library ieee; -- component #1 +vhdl code use ieee.std_logic_1164.all; +vhdl blank +vhdl code entity OR_GATE is +vhdl code port( X: in std_logic; +vhdl code Y: in std_logic; +vhdl code F2: out std_logic +vhdl code ); +vhdl code end OR_GATE; +vhdl blank +vhdl code architecture behv of OR_GATE is +vhdl code begin +vhdl code process(X,Y) +vhdl code begin +vhdl code F2 <= X or Y; -- behavior des. +vhdl code end process; +vhdl code end behv; +vhdl blank +vhdl comment ------------------------------------------------------------- +vhdl blank +vhdl code library ieee; -- component #2 +vhdl code use ieee.std_logic_1164.all; +vhdl blank +vhdl code entity AND_GATE is +vhdl code port( A: in std_logic; +vhdl code B: in std_logic; +vhdl code F1: out std_logic +vhdl code ); +vhdl code end AND_GATE; +vhdl blank +vhdl code architecture behv of AND_GATE is +vhdl code begin +vhdl code process(A,B) +vhdl code begin +vhdl code F1 <= A and B; -- behavior des. +vhdl code end process; +vhdl code end behv; +vhdl blank +vhdl comment -------------------------------------------------------------- +vhdl blank +vhdl code library ieee; -- top level circuit +vhdl code use ieee.std_logic_1164.all; +vhdl code use work.all; +vhdl blank +vhdl code entity comb_ckt is +vhdl code port( input1: in std_logic; +vhdl code input2: in std_logic; +vhdl code input3: in std_logic; +vhdl code output: out std_logic +vhdl code ); +vhdl code end comb_ckt; +vhdl blank +vhdl code architecture struct of comb_ckt is +vhdl blank +vhdl code component AND_GATE is -- as entity of AND_GATE +vhdl code port( A: in std_logic; +vhdl code B: in std_logic; +vhdl code F1: out std_logic +vhdl code ); +vhdl code end component; +vhdl blank +vhdl code component OR_GATE is -- as entity of OR_GATE +vhdl code port( X: in std_logic; +vhdl code Y: in std_logic; +vhdl code F2: out std_logic +vhdl code ); +vhdl code end component; +vhdl blank +vhdl code signal wire: std_logic; -- signal just like wire +vhdl blank +vhdl code begin +vhdl blank +vhdl comment -- use sign "=>" to clarify the pin mapping +vhdl blank +vhdl code Gate1: AND_GATE port map (A=>input1, B=>input2, F1=>wire); +vhdl code Gate2: OR_GATE port map (X=>wire, Y=>input3, F2=>output); +vhdl blank +vhdl code end struct; +vhdl blank +vhdl comment ---------------------------------------------------------------- diff --git a/test/expected_dir/vhdl1.vhd/vhdl/blanks b/test/expected_dir/vhdl1.vhd/vhdl/blanks deleted file mode 100644 index dec2bf5..0000000 --- a/test/expected_dir/vhdl1.vhd/vhdl/blanks +++ /dev/null @@ -1 +0,0 @@ -19 \ No newline at end of file diff --git a/test/expected_dir/vhdl1.vhd/vhdl/code b/test/expected_dir/vhdl1.vhd/vhdl/code deleted file mode 100644 index cfeaccf..0000000 --- a/test/expected_dir/vhdl1.vhd/vhdl/code +++ /dev/null @@ -1,58 +0,0 @@ -library ieee; -- component #1 -use ieee.std_logic_1164.all; -entity OR_GATE is -port( X: in std_logic; -Y: in std_logic; -F2: out std_logic -); -end OR_GATE; -architecture behv of OR_GATE is -begin -process(X,Y) -begin -F2 <= X or Y; -- behavior des. -end process; -end behv; -library ieee; -- component #2 -use ieee.std_logic_1164.all; -entity AND_GATE is -port( A: in std_logic; -B: in std_logic; -F1: out std_logic -); -end AND_GATE; -architecture behv of AND_GATE is -begin -process(A,B) -begin -F1 <= A and B; -- behavior des. -end process; -end behv; -library ieee; -- top level circuit -use ieee.std_logic_1164.all; -use work.all; -entity comb_ckt is -port( input1: in std_logic; -input2: in std_logic; -input3: in std_logic; -output: out std_logic -); -end comb_ckt; -architecture struct of comb_ckt is -component AND_GATE is -- as entity of AND_GATE -port( A: in std_logic; -B: in std_logic; -F1: out std_logic -); -end component; -component OR_GATE is -- as entity of OR_GATE -port( X: in std_logic; -Y: in std_logic; -F2: out std_logic -); -end component; -signal wire: std_logic; -- signal just like wire -begin -Gate1: AND_GATE port map (A=>input1, B=>input2, F1=>wire); -Gate2: OR_GATE port map (X=>wire, Y=>input3, F2=>output); -end struct; diff --git a/test/expected_dir/vhdl1.vhd/vhdl/comment b/test/expected_dir/vhdl1.vhd/vhdl/comment deleted file mode 100644 index 4430e90..0000000 --- a/test/expected_dir/vhdl1.vhd/vhdl/comment +++ /dev/null @@ -1,15 +0,0 @@ ------------------------------------------------------------- --- Combinational Logic Design --- (ESD book figure 2.4) --- by Weijun Zhang, 04/2001 --- --- A simple example of VHDL Structure Modeling --- we might define two components in two separate files, --- in main file, we use port map statement to instantiate --- the mapping relationship between each components --- and the entire circuit. ------------------------------------------------------------- -------------------------------------------------------------- --------------------------------------------------------------- --- use sign "=>" to clarify the pin mapping ----------------------------------------------------------------- diff --git a/test/expected_dir/vhdl1.vhdl b/test/expected_dir/vhdl1.vhdl new file mode 100644 index 0000000..379aaa6 --- /dev/null +++ b/test/expected_dir/vhdl1.vhdl @@ -0,0 +1,40 @@ +vhdl code library ieee; +vhdl code use ieee.std_logic_1164.all; +vhdl blank +vhdl code entity tb is +vhdl code end tb; +vhdl blank +vhdl code architecture behav of tb is +vhdl blank +vhdl comment -- toggle period +vhdl code constant period_c : time := 1 ms; +vhdl blank +vhdl comment -- we'll be poking on this signal +vhdl code signal toggle_s : std_logic_vector(1 downto 0) := "01"; +vhdl blank +vhdl code begin +vhdl blank +vhdl comment ----------------------------------------------------------------------------- +vhdl comment -- Process toggle +vhdl comment -- +vhdl comment -- Purpose: +vhdl comment -- Flip the toggle_s signal periodically. +vhdl comment -- +vhdl code toggle: process +vhdl code begin +vhdl blank +vhdl code wait for period_c/2; +vhdl code toggle_s <= not toggle_s; +vhdl blank +vhdl code end process toggle; +vhdl comment -- +vhdl comment ----------------------------------------------------------------------------- +vhdl blank +vhdl code end behav; +vhdl blank +vhdl code configuration tb_behav_c0 of tb is +vhdl blank +vhdl code for behav +vhdl code end for; +vhdl blank +vhdl code end tb_behav_c0; diff --git a/test/expected_dir/vhdl1.vhdl/vhdl/blanks b/test/expected_dir/vhdl1.vhdl/vhdl/blanks deleted file mode 100644 index 3cacc0b..0000000 --- a/test/expected_dir/vhdl1.vhdl/vhdl/blanks +++ /dev/null @@ -1 +0,0 @@ -12 \ No newline at end of file diff --git a/test/expected_dir/vhdl1.vhdl/vhdl/code b/test/expected_dir/vhdl1.vhdl/vhdl/code deleted file mode 100644 index 2bbdc82..0000000 --- a/test/expected_dir/vhdl1.vhdl/vhdl/code +++ /dev/null @@ -1,18 +0,0 @@ -library ieee; -use ieee.std_logic_1164.all; -entity tb is -end tb; -architecture behav of tb is -constant period_c : time := 1 ms; -signal toggle_s : std_logic_vector(1 downto 0) := "01"; -begin -toggle: process -begin -wait for period_c/2; -toggle_s <= not toggle_s; -end process toggle; -end behav; -configuration tb_behav_c0 of tb is -for behav -end for; -end tb_behav_c0; diff --git a/test/expected_dir/vhdl1.vhdl/vhdl/comment b/test/expected_dir/vhdl1.vhdl/vhdl/comment deleted file mode 100644 index 98b17ed..0000000 --- a/test/expected_dir/vhdl1.vhdl/vhdl/comment +++ /dev/null @@ -1,10 +0,0 @@ --- toggle period --- we'll be poking on this signal ------------------------------------------------------------------------------ --- Process toggle --- --- Purpose: --- Flip the toggle_s signal periodically. --- --- ------------------------------------------------------------------------------ diff --git a/test/expected_dir/visual_basic.bas b/test/expected_dir/visual_basic.bas new file mode 100644 index 0000000..c8331c6 --- /dev/null +++ b/test/expected_dir/visual_basic.bas @@ -0,0 +1,60 @@ +visualbasic code VERSION 5.00 +visualbasic code Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" +visualbasic code Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" +visualbasic code Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX" +visualbasic code Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX" +visualbasic code Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" +visualbasic code Begin VB.Form frmMain +visualbasic code BorderStyle = 1 'Fixed Single +visualbasic code ClientHeight = 6555 +visualbasic code ClientLeft = 150 +visualbasic code ClientTop = 435 +visualbasic code ClientWidth = 10620 +visualbasic code LinkTopic = "Form1" +visualbasic code MaxButton = 0 'False +visualbasic code MinButton = 0 'False +visualbasic code ScaleHeight = 6555 +visualbasic code ScaleWidth = 10620 +visualbasic code StartUpPosition = 3 'Windows Default +visualbasic code Attribute VB_Name = "frmMain" +visualbasic code Attribute VB_GlobalNameSpace = False +visualbasic code Attribute VB_Creatable = False +visualbasic code Attribute VB_PredeclaredId = True +visualbasic code Attribute VB_Exposed = False +visualbasic comment '--------------------------------------------------------------------------- +visualbasic comment ' +visualbasic comment ' SOURCE FILE NAME: Demo.frm +visualbasic comment ' +visualbasic comment ' SAMPLE: Visual Basic Demo with user interface for the sample modules +visualbasic comment ' +visualbasic comment ' For more information about samples, refer to the README file. +visualbasic comment ' +visualbasic comment '--------------------------------------------------------------------------- +visualbasic blank +visualbasic code Option Explicit +visualbasic blank +visualbasic code Private con As ADODB.Connection +visualbasic code Private rst As ADODB.Recordset +visualbasic code Private strMsgText As String +visualbasic code Private wShowInstructions As Integer +visualbasic blank +visualbasic comment 'This procedure calls ConnectOLEDB() in the module dbConn to get +visualbasic comment 'a connection object. +visualbasic code Private Sub cmdConnectOLEDB_Click() +visualbasic comment 'define the error handler +visualbasic comment ' On Error GoTo cmdConnectOLEDB_Error +visualbasic blank +visualbasic comment 'connect to database +visualbasic code Set con = ConnectOLEDB() +visualbasic blank +visualbasic comment 'generate a message of success +visualbasic code sbrStatus.Panels(1).Text = "Connect to sample database succeeded!" +visualbasic blank +visualbasic comment 'config status of the buttons +visualbasic code EnableButtons +visualbasic blank +visualbasic comment 'show instructions +visualbasic code If wShowInstructions = vbYes Then +visualbasic code ShowConnectionInstruction +visualbasic code End If +visualbasic code End Sub diff --git a/test/expected_dir/visual_basic.bas/visualbasic/blanks b/test/expected_dir/visual_basic.bas/visualbasic/blanks deleted file mode 100644 index c793025..0000000 --- a/test/expected_dir/visual_basic.bas/visualbasic/blanks +++ /dev/null @@ -1 +0,0 @@ -7 \ No newline at end of file diff --git a/test/expected_dir/visual_basic.bas/visualbasic/code b/test/expected_dir/visual_basic.bas/visualbasic/code deleted file mode 100644 index d0fa5b8..0000000 --- a/test/expected_dir/visual_basic.bas/visualbasic/code +++ /dev/null @@ -1,36 +0,0 @@ -VERSION 5.00 -Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" -Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" -Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX" -Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX" -Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" -Begin VB.Form frmMain -BorderStyle = 1 'Fixed Single -ClientHeight = 6555 -ClientLeft = 150 -ClientTop = 435 -ClientWidth = 10620 -LinkTopic = "Form1" -MaxButton = 0 'False -MinButton = 0 'False -ScaleHeight = 6555 -ScaleWidth = 10620 -StartUpPosition = 3 'Windows Default -Attribute VB_Name = "frmMain" -Attribute VB_GlobalNameSpace = False -Attribute VB_Creatable = False -Attribute VB_PredeclaredId = True -Attribute VB_Exposed = False -Option Explicit -Private con As ADODB.Connection -Private rst As ADODB.Recordset -Private strMsgText As String -Private wShowInstructions As Integer -Private Sub cmdConnectOLEDB_Click() -Set con = ConnectOLEDB() -sbrStatus.Panels(1).Text = "Connect to sample database succeeded!" -EnableButtons -If wShowInstructions = vbYes Then -ShowConnectionInstruction -End If -End Sub diff --git a/test/expected_dir/visual_basic.bas/visualbasic/comment b/test/expected_dir/visual_basic.bas/visualbasic/comment deleted file mode 100644 index fc9649a..0000000 --- a/test/expected_dir/visual_basic.bas/visualbasic/comment +++ /dev/null @@ -1,17 +0,0 @@ -'--------------------------------------------------------------------------- -' -' SOURCE FILE NAME: Demo.frm -' -' SAMPLE: Visual Basic Demo with user interface for the sample modules -' -' For more information about samples, refer to the README file. -' -'--------------------------------------------------------------------------- -'This procedure calls ConnectOLEDB() in the module dbConn to get -'a connection object. -'define the error handler -' On Error GoTo cmdConnectOLEDB_Error -'connect to database -'generate a message of success -'config status of the buttons -'show instructions diff --git a/test/expected_dir/xml1.xml b/test/expected_dir/xml1.xml new file mode 100644 index 0000000..db38a87 --- /dev/null +++ b/test/expected_dir/xml1.xml @@ -0,0 +1,14 @@ +xml code +xml comment +xml code +xml code ]]> +xml blank +xml code +xml comment +xml code +xml code +xml blank diff --git a/test/expected_dir/xml1.xml/xml/blanks b/test/expected_dir/xml1.xml/xml/blanks deleted file mode 100644 index d8263ee..0000000 --- a/test/expected_dir/xml1.xml/xml/blanks +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/test/expected_dir/xml1.xml/xml/code b/test/expected_dir/xml1.xml/xml/code deleted file mode 100644 index 844c38e..0000000 --- a/test/expected_dir/xml1.xml/xml/code +++ /dev/null @@ -1,7 +0,0 @@ - - -]]> - - - diff --git a/test/expected_dir/xml1.xml/xml/comment b/test/expected_dir/xml1.xml/xml/comment deleted file mode 100644 index 4cff3c6..0000000 --- a/test/expected_dir/xml1.xml/xml/comment +++ /dev/null @@ -1,5 +0,0 @@ - almost done with comment ---> - diff --git a/test/expected_licenses/affero_1 b/test/expected_licenses/affero_1 new file mode 100644 index 0000000..077775a --- /dev/null +++ b/test/expected_licenses/affero_1 @@ -0,0 +1 @@ +affero diff --git a/test/expected_licenses/avr-drv b/test/expected_licenses/avr-drv new file mode 100644 index 0000000..2758ff2 --- /dev/null +++ b/test/expected_licenses/avr-drv @@ -0,0 +1 @@ +bsd_ish diff --git a/test/expected_licenses/boost_t1 b/test/expected_licenses/boost_t1 new file mode 100644 index 0000000..d579dbe --- /dev/null +++ b/test/expected_licenses/boost_t1 @@ -0,0 +1 @@ +boost diff --git a/test/expected_licenses/boost_t2 b/test/expected_licenses/boost_t2 new file mode 100644 index 0000000..d579dbe --- /dev/null +++ b/test/expected_licenses/boost_t2 @@ -0,0 +1 @@ +boost diff --git a/test/expected_licenses/bsd_2clause_ish_t2 b/test/expected_licenses/bsd_2clause_ish_t2 deleted file mode 100644 index a7fe7c3..0000000 --- a/test/expected_licenses/bsd_2clause_ish_t2 +++ /dev/null @@ -1 +0,0 @@ -bsd_2clause_ish diff --git a/test/expected_licenses/bsd_ish_t3 b/test/expected_licenses/bsd_ish_t3 new file mode 100644 index 0000000..2758ff2 --- /dev/null +++ b/test/expected_licenses/bsd_ish_t3 @@ -0,0 +1 @@ +bsd_ish diff --git a/test/expected_licenses/cecill b/test/expected_licenses/cecill new file mode 100644 index 0000000..1e5183e --- /dev/null +++ b/test/expected_licenses/cecill @@ -0,0 +1 @@ +cecill diff --git a/test/expected_licenses/cecill-b b/test/expected_licenses/cecill-b new file mode 100644 index 0000000..3621136 --- /dev/null +++ b/test/expected_licenses/cecill-b @@ -0,0 +1 @@ +cecill_b diff --git a/test/expected_licenses/cecill-c b/test/expected_licenses/cecill-c new file mode 100644 index 0000000..a380ed5 --- /dev/null +++ b/test/expected_licenses/cecill-c @@ -0,0 +1 @@ +cecill_c diff --git a/test/expected_licenses/gpl3_or_later_t3 b/test/expected_licenses/gpl3_or_later_t3 new file mode 100644 index 0000000..9765a18 --- /dev/null +++ b/test/expected_licenses/gpl3_or_later_t3 @@ -0,0 +1 @@ +gpl3_or_later diff --git a/test/expected_licenses/gpl3_t2 b/test/expected_licenses/gpl3_t2 new file mode 100644 index 0000000..1754a00 --- /dev/null +++ b/test/expected_licenses/gpl3_t2 @@ -0,0 +1,2 @@ +bsd +gpl3 diff --git a/test/expected_licenses/gpl_line_wrap_2 b/test/expected_licenses/gpl_line_wrap_2 deleted file mode 100644 index fc03356..0000000 --- a/test/expected_licenses/gpl_line_wrap_2 +++ /dev/null @@ -1 +0,0 @@ -gpl diff --git a/test/expected_licenses/i9_license_t1 b/test/expected_licenses/i9_license_t1 new file mode 100644 index 0000000..ac0b8e1 --- /dev/null +++ b/test/expected_licenses/i9_license_t1 @@ -0,0 +1,2 @@ +i9_license +mit diff --git a/test/expected_licenses/i9_license_t2 b/test/expected_licenses/i9_license_t2 new file mode 100644 index 0000000..7fa8801 --- /dev/null +++ b/test/expected_licenses/i9_license_t2 @@ -0,0 +1 @@ +i9_license diff --git a/test/expected_licenses/lgpl3_t2 b/test/expected_licenses/lgpl3_t2 new file mode 100644 index 0000000..52b7d89 --- /dev/null +++ b/test/expected_licenses/lgpl3_t2 @@ -0,0 +1 @@ +lgpl3 diff --git a/test/expected_licenses/wtfpl b/test/expected_licenses/wtfpl new file mode 100644 index 0000000..c0f1ca9 --- /dev/null +++ b/test/expected_licenses/wtfpl @@ -0,0 +1 @@ +wtfpl_2 diff --git a/test/gestalt_files/asp_net/test.aspx b/test/gestalt_files/asp_net/test.aspx new file mode 100644 index 0000000..e69de29 diff --git a/test/gestalt_files/cakephp/foo.php b/test/gestalt_files/cakephp/foo.php new file mode 100644 index 0000000..62a3a9d --- /dev/null +++ b/test/gestalt_files/cakephp/foo.php @@ -0,0 +1,5 @@ + diff --git a/test/gestalt_files/drupal/bar.php b/test/gestalt_files/drupal/bar.php new file mode 100644 index 0000000..af5d41f --- /dev/null +++ b/test/gestalt_files/drupal/bar.php @@ -0,0 +1,4 @@ + diff --git a/test/gestalt_files/eclipse/.project b/test/gestalt_files/eclipse/.project new file mode 100755 index 0000000..64e993c --- /dev/null +++ b/test/gestalt_files/eclipse/.project @@ -0,0 +1,17 @@ + + + sample + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/test/gestalt_files/eclipse_platform/main.java b/test/gestalt_files/eclipse_platform/main.java new file mode 100644 index 0000000..2798a90 --- /dev/null +++ b/test/gestalt_files/eclipse_platform/main.java @@ -0,0 +1,12 @@ +/******************************************************************************* + * Gibberish Code Copyrighted Just For The Hell Of It. + ******************************************************************************/ + package net.ohloh.www; + + import java.text.SimpleDateFormat; + import java.util.Map; + import org.eclipse.core.lotsa_stuff; + + public class AptPlugin extends Plugin { + public static final String PLUGIN_ID = "org.eclipse.jdt.apt.core"; //$NON-NLS-1$ + } diff --git a/test/gestalt_files/gtk/simple.c b/test/gestalt_files/gtk/simple.c new file mode 100644 index 0000000..2910064 --- /dev/null +++ b/test/gestalt_files/gtk/simple.c @@ -0,0 +1,13 @@ +#include +int main(int argc, char *argv[]) +{ + GtkWidget *gtkWindow; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_show(window); + + gtk_main(); + return 0; +} diff --git a/test/gestalt_files/jquery/jquery-1.2.6.min.js b/test/gestalt_files/jquery/jquery-1.2.6.min.js new file mode 100644 index 0000000..0b035d7 --- /dev/null +++ b/test/gestalt_files/jquery/jquery-1.2.6.min.js @@ -0,0 +1 @@ +i = 1; diff --git a/test/gestalt_files/kde/foo.c b/test/gestalt_files/kde/foo.c new file mode 100644 index 0000000..ec50a2d --- /dev/null +++ b/test/gestalt_files/kde/foo.c @@ -0,0 +1 @@ +#include diff --git a/test/gestalt_files/mac/foo.c b/test/gestalt_files/mac/foo.c new file mode 100644 index 0000000..c1e580d --- /dev/null +++ b/test/gestalt_files/mac/foo.c @@ -0,0 +1 @@ +AppleEvent tAppleEvent; diff --git a/test/gestalt_files/moodle/moodle.php b/test/gestalt_files/moodle/moodle.php new file mode 100644 index 0000000..1ecdedd --- /dev/null +++ b/test/gestalt_files/moodle/moodle.php @@ -0,0 +1,8 @@ + diff --git a/test/gestalt_files/msdos/bar.c b/test/gestalt_files/msdos/bar.c new file mode 100644 index 0000000..03949f9 --- /dev/null +++ b/test/gestalt_files/msdos/bar.c @@ -0,0 +1 @@ +#include "MSDOS" diff --git a/test/gestalt_files/msdos/foo.c b/test/gestalt_files/msdos/foo.c new file mode 100644 index 0000000..311ff65 --- /dev/null +++ b/test/gestalt_files/msdos/foo.c @@ -0,0 +1 @@ +#include "__MSDOS__" diff --git a/test/gestalt_files/netbeans/nbplatform/foo b/test/gestalt_files/netbeans/nbplatform/foo new file mode 100644 index 0000000..e69de29 diff --git a/test/gestalt_files/netbeans/nbplatform/project.xml b/test/gestalt_files/netbeans/nbplatform/project.xml new file mode 100644 index 0000000..f5ec34c --- /dev/null +++ b/test/gestalt_files/netbeans/nbplatform/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.apisupport.project.suite + + + sample + + + diff --git a/test/gestalt_files/pear/Sample.class.php b/test/gestalt_files/pear/Sample.class.php new file mode 100644 index 0000000..243e5dd --- /dev/null +++ b/test/gestalt_files/pear/Sample.class.php @@ -0,0 +1,10 @@ + diff --git a/test/gestalt_files/pear/package.xml b/test/gestalt_files/pear/package.xml new file mode 100644 index 0000000..942a309 --- /dev/null +++ b/test/gestalt_files/pear/package.xml @@ -0,0 +1,9 @@ + + + diff --git a/test/gestalt_files/php/main.php b/test/gestalt_files/php/main.php new file mode 100644 index 0000000..2830618 --- /dev/null +++ b/test/gestalt_files/php/main.php @@ -0,0 +1,5 @@ + diff --git a/test/gestalt_files/plist/Info.plist.in b/test/gestalt_files/plist/Info.plist.in new file mode 100644 index 0000000..eb7c10a --- /dev/null +++ b/test/gestalt_files/plist/Info.plist.in @@ -0,0 +1,8 @@ + + + + + CFBundleDevelopmentRegion + English + + diff --git a/test/gestalt_files/posix/configure.in b/test/gestalt_files/posix/configure.in new file mode 100644 index 0000000..0e76864 --- /dev/null +++ b/test/gestalt_files/posix/configure.in @@ -0,0 +1 @@ +a line of code diff --git a/test/gestalt_files/posix/foo.c b/test/gestalt_files/posix/foo.c new file mode 100644 index 0000000..dcbbbf8 --- /dev/null +++ b/test/gestalt_files/posix/foo.c @@ -0,0 +1,102 @@ +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; +int = 0; diff --git a/test/gestalt_files/posix/foo.rb b/test/gestalt_files/posix/foo.rb new file mode 100644 index 0000000..7505dbc --- /dev/null +++ b/test/gestalt_files/posix/foo.rb @@ -0,0 +1,4 @@ +# this is ruby code +class Foo + attr_reader :bar +end diff --git a/test/gestalt_files/python/hello_world.py b/test/gestalt_files/python/hello_world.py new file mode 100644 index 0000000..18d9f87 --- /dev/null +++ b/test/gestalt_files/python/hello_world.py @@ -0,0 +1 @@ +print "Hello, World!" diff --git a/test/gestalt_files/rails/foo.rb b/test/gestalt_files/rails/foo.rb new file mode 100644 index 0000000..7f10e75 --- /dev/null +++ b/test/gestalt_files/rails/foo.rb @@ -0,0 +1,3 @@ +# we're impersonating a rails app +RAILS_ROOT = '/' +some_rails_code = "true" diff --git a/test/gestalt_files/ruby_just_enough/foo.c b/test/gestalt_files/ruby_just_enough/foo.c new file mode 100644 index 0000000..64e6c46 --- /dev/null +++ b/test/gestalt_files/ruby_just_enough/foo.c @@ -0,0 +1,75 @@ +int i = 1; +int i = 2; +int i = 3; +int i = 4; +int i = 5; +int i = 6; +int i = 7; +int i = 8; +int i = 9; +int i = 10; +int i = 11; +int i = 12; +int i = 13; +int i = 14; +int i = 15; +int i = 16; +int i = 17; +int i = 18; +int i = 19; +int i = 20; +int i = 21; +int i = 22; +int i = 23; +int i = 24; +int i = 25; +int i = 26; +int i = 27; +int i = 28; +int i = 29; +int i = 30; +int i = 31; +int i = 32; +int i = 33; +int i = 34; +int i = 35; +int i = 36; +int i = 37; +int i = 38; +int i = 39; +int i = 40; +int i = 41; +int i = 42; +int i = 43; +int i = 44; +int i = 45; +int i = 46; +int i = 47; +int i = 48; +int i = 49; +int i = 50; +int i = 51; +int i = 52; +int i = 53; +int i = 54; +int i = 55; +int i = 56; +int i = 57; +int i = 58; +int i = 59; +int i = 60; +int i = 61; +int i = 62; +int i = 63; +int i = 64; +int i = 65; +int i = 66; +int i = 67; +int i = 68; +int i = 69; +int i = 70; +int i = 71; +int i = 72; +int i = 73; +int i = 74; +int i = 75; diff --git a/test/gestalt_files/ruby_just_enough/foo.rb b/test/gestalt_files/ruby_just_enough/foo.rb new file mode 100644 index 0000000..6cfd7a3 --- /dev/null +++ b/test/gestalt_files/ruby_just_enough/foo.rb @@ -0,0 +1,15 @@ +a = 1 +a = 2 +a = 3 +a = 4 +a = 5 +a = 6 +a = 7 +a = 8 +a = 9 +a = 10 +a = 11 +a = 12 +a = 13 +a = 14 +a = 15 diff --git a/test/gestalt_files/ruby_not_enough/foo.c b/test/gestalt_files/ruby_not_enough/foo.c new file mode 100644 index 0000000..bc21e75 --- /dev/null +++ b/test/gestalt_files/ruby_not_enough/foo.c @@ -0,0 +1,87 @@ +int i = 1; +int i = 2; +int i = 3; +int i = 4; +int i = 5; +int i = 6; +int i = 7; +int i = 8; +int i = 9; +int i = 10; +int i = 11; +int i = 12; +int i = 13; +int i = 14; +int i = 15; +int i = 16; +int i = 17; +int i = 18; +int i = 19; +int i = 20; +int i = 21; +int i = 22; +int i = 23; +int i = 24; +int i = 25; +int i = 26; +int i = 27; +int i = 28; +int i = 29; +int i = 30; +int i = 31; +int i = 32; +int i = 33; +int i = 34; +int i = 35; +int i = 36; +int i = 37; +int i = 38; +int i = 39; +int i = 40; +int i = 41; +int i = 42; +int i = 43; +int i = 44; +int i = 45; +int i = 46; +int i = 47; +int i = 48; +int i = 49; +int i = 50; +int i = 51; +int i = 52; +int i = 53; +int i = 54; +int i = 55; +int i = 56; +int i = 57; +int i = 58; +int i = 59; +int i = 60; +int i = 61; +int i = 62; +int i = 63; +int i = 64; +int i = 65; +int i = 66; +int i = 67; +int i = 68; +int i = 69; +int i = 70; +int i = 71; +int i = 72; +int i = 73; +int i = 74; +int i = 75; +int i = 76; +int i = 77; +int i = 78; +int i = 79; +int i = 80; +int i = 81; +int i = 82; +int i = 83; +int i = 84; +int i = 85; +int i = 86; +int i = 87; diff --git a/test/gestalt_files/ruby_not_enough/foo.rb b/test/gestalt_files/ruby_not_enough/foo.rb new file mode 100644 index 0000000..6cfd7a3 --- /dev/null +++ b/test/gestalt_files/ruby_not_enough/foo.rb @@ -0,0 +1,15 @@ +a = 1 +a = 2 +a = 3 +a = 4 +a = 5 +a = 6 +a = 7 +a = 8 +a = 9 +a = 10 +a = 11 +a = 12 +a = 13 +a = 14 +a = 15 diff --git a/test/gestalt_files/spring_framework/main.java b/test/gestalt_files/spring_framework/main.java new file mode 100644 index 0000000..d762779 --- /dev/null +++ b/test/gestalt_files/spring_framework/main.java @@ -0,0 +1,7 @@ +class JavaClass +{ + int i = 1; + int i = 2; + int i = 3; +} + diff --git a/test/gestalt_files/spring_framework/spring.jar b/test/gestalt_files/spring_framework/spring.jar new file mode 100644 index 0000000..e69de29 diff --git a/test/gestalt_files/symfony/config.php b/test/gestalt_files/symfony/config.php new file mode 100644 index 0000000..9ba03b2 --- /dev/null +++ b/test/gestalt_files/symfony/config.php @@ -0,0 +1,2 @@ + diff --git a/test/gestalt_files/weblogic_maven/foo.java b/test/gestalt_files/weblogic_maven/foo.java new file mode 100644 index 0000000..a6f7059 --- /dev/null +++ b/test/gestalt_files/weblogic_maven/foo.java @@ -0,0 +1,4 @@ +/* Just a comment */ +{ + return a_few_lines_of_java_to_trigger_the_java_platform(); +} diff --git a/test/gestalt_files/weblogic_maven/pom.xml b/test/gestalt_files/weblogic_maven/pom.xml new file mode 100644 index 0000000..041a4ea --- /dev/null +++ b/test/gestalt_files/weblogic_maven/pom.xml @@ -0,0 +1,9 @@ + + + + org.codehaus.mojo + weblogic-maven-plugin + + + diff --git a/test/gestalt_files/websphere/foo.java b/test/gestalt_files/websphere/foo.java new file mode 100644 index 0000000..a6f7059 --- /dev/null +++ b/test/gestalt_files/websphere/foo.java @@ -0,0 +1,4 @@ +/* Just a comment */ +{ + return a_few_lines_of_java_to_trigger_the_java_platform(); +} diff --git a/test/gestalt_files/websphere/ibm-webservices-bnd.xmi b/test/gestalt_files/websphere/ibm-webservices-bnd.xmi new file mode 100644 index 0000000..e69de29 diff --git a/test/gestalt_files/win32_enough/bar.c b/test/gestalt_files/win32_enough/bar.c new file mode 100644 index 0000000..e7919b8 --- /dev/null +++ b/test/gestalt_files/win32_enough/bar.c @@ -0,0 +1,3 @@ +// a commented WndProc +WndProc *wndproc; + diff --git a/test/gestalt_files/win32_enough/foo.c b/test/gestalt_files/win32_enough/foo.c new file mode 100644 index 0000000..13de7b2 --- /dev/null +++ b/test/gestalt_files/win32_enough/foo.c @@ -0,0 +1,3 @@ +// another commented WndProc +WndProc *wndproc; + diff --git a/test/gestalt_files/win32_not_enough/foo.c b/test/gestalt_files/win32_not_enough/foo.c new file mode 100644 index 0000000..e7919b8 --- /dev/null +++ b/test/gestalt_files/win32_not_enough/foo.c @@ -0,0 +1,3 @@ +// a commented WndProc +WndProc *wndproc; + diff --git a/test/gestalt_files/wpf/wpf.xaml b/test/gestalt_files/wpf/wpf.xaml new file mode 100644 index 0000000..4275c95 --- /dev/null +++ b/test/gestalt_files/wpf/wpf.xaml @@ -0,0 +1,6 @@ + + + diff --git a/test/gestalt_files/wx_widgets/main.h b/test/gestalt_files/wx_widgets/main.h new file mode 100644 index 0000000..7b1cc39 --- /dev/null +++ b/test/gestalt_files/wx_widgets/main.h @@ -0,0 +1,3 @@ +/* some random includes (and one that's not so random) */ +#include +#include "wx/window.h" diff --git a/test/gestalt_files/xwindows/foo.c b/test/gestalt_files/xwindows/foo.c new file mode 100644 index 0000000..271aa6c --- /dev/null +++ b/test/gestalt_files/xwindows/foo.c @@ -0,0 +1 @@ +#include diff --git a/test/gestalt_files/zend_framework/application/controllers/ZendWildfirePluginFirePhpController.php b/test/gestalt_files/zend_framework/application/controllers/ZendWildfirePluginFirePhpController.php new file mode 100644 index 0000000..8273004 --- /dev/null +++ b/test/gestalt_files/zend_framework/application/controllers/ZendWildfirePluginFirePhpController.php @@ -0,0 +1,50 @@ += 42; # variable definition. +minimize o: x; diff --git a/test/src_dir/assembler6502.as8 b/test/src_dir/assembler6502.as8 new file mode 100644 index 0000000..09846ae --- /dev/null +++ b/test/src_dir/assembler6502.as8 @@ -0,0 +1,21 @@ +; "Hello world" in 6502 assembly language for 8-bit Atari. +; Assembler: http://xasm.atari.org/ or http://mads.atari8.info/ + + org $3000 +main lda #$21 + sta $22f + lda #
dl + sta $231 + jmp * + +text dta d' HELLO, ',d'WORLD! '* + +; Display List +dl dta b($70),b($70),b($70),b($47),a(text),b($41),a(dl) + + org $2e0 + dta a(main) + + end diff --git a/test/src_dir/assembler6502.asx b/test/src_dir/assembler6502.asx new file mode 100644 index 0000000..09846ae --- /dev/null +++ b/test/src_dir/assembler6502.asx @@ -0,0 +1,21 @@ +; "Hello world" in 6502 assembly language for 8-bit Atari. +; Assembler: http://xasm.atari.org/ or http://mads.atari8.info/ + + org $3000 +main lda #$21 + sta $22f + lda #
dl + sta $231 + jmp * + +text dta d' HELLO, ',d'WORLD! '* + +; Display List +dl dta b($70),b($70),b($70),b($47),a(text),b($41),a(dl) + + org $2e0 + dta a(main) + + end diff --git a/test/src_dir/augeas.aug b/test/src_dir/augeas.aug new file mode 100644 index 0000000..a4e3b2d --- /dev/null +++ b/test/src_dir/augeas.aug @@ -0,0 +1,14 @@ +(** documentation *) +module Augeas = +autoload xfm +(**/**) +(* extra comment *) + +(* multiline + comment*) +let lns = Shellvars.lns + +(* recursion in (* a + comment *) to complicate things *) +let filter = incl "/foo/bar" +let xfm = transform lns filter diff --git a/test/src_dir/b.bfpp b/test/src_dir/b.bfpp new file mode 100644 index 0000000..90d2653 --- /dev/null +++ b/test/src_dir/b.bfpp @@ -0,0 +1,54 @@ + += comment +>++++++[>+++[<<++++>>-]<-]<. +>+++++[<++++++>-]<-. ++++++++. +. ++++. +>>++++[<++++++>-]<++[<--->-]<-. +>>++[<+++++>-]<+[<+++++>-]<. +>++++[<++++++>-]<. ++++. +------. +>++[<---->-]<. +>>++++[<++++>-]<+[<---->-]<. +>+++++++[<++++++>-]<-. +>++++++[<++++++>-]<+. +>>++++[<++++++>-]<++[<--->-]<. +>+++++[<+++++++>-]<-. +>++++[>++++[<<+++>>-]<-]<. +>++++[<---->-]<-. +>++[<++++>-]<. ++++++. +>++[<---->-]<. +>+++[<+++++>-]<. +>+++[<------>-]<. +>++[<++++>-]<. +>++++[>++++[<<---->>-]<-]<. +. +>++[<----->-]<. +. +. +. +. +[-] + = [-] is used to clear a cell + += Try to open b file +>+++++++[>+++++++[<<++>>-]<-]<. +#[ + >>++++[<++++>-]<+[<++++++>-]<. + +++. + +++. + -------. + >>++++[<++++++>-]<-[<--->-]<. + >>++[<+++++>-]<+[<++++++>-]<. + >>++[<+++++>-]<+[<------>-]<. + >>++++[<++++++>-]<++[<+++>-]<+. + +. + >++[<----->-]<-. + >+++[<+++>-]<. + >+++[<--->-]<. + -. +#] +@include(nothing.bfpp) diff --git a/test/src_dir/bat1.bat b/test/src_dir/bat1.bat index d04519b..acb3486 100644 --- a/test/src_dir/bat1.bat +++ b/test/src_dir/bat1.bat @@ -1,6 +1,11 @@ REM comment 1 rem comment 2 rEm comment 3 +rEm.comment 4 +Rem=comment 5 +@Rem comment 6 +@reM=comment 7 +::comment 8 echo not a rem comment! diff --git a/test/src_dir/blitzmax.bmx b/test/src_dir/blitzmax.bmx new file mode 100644 index 0000000..da4ae51 --- /dev/null +++ b/test/src_dir/blitzmax.bmx @@ -0,0 +1,32 @@ +' +' Comments +' +SuperStrict + +Rem +bbdoc: docs +End Rem +Module bah.fish + +Import BRL.StandardIO + +Import "test.bmx" ' comment + +rem +some comments + + +Type blah +still in comments +End Type + +endrem + +Type TABC + + Method hello() + End Method + +End Type + +print "hello rem fish ' " diff --git a/test/src_dir/brainfuck.bf b/test/src_dir/brainfuck.bf new file mode 100644 index 0000000..0eb2911 --- /dev/null +++ b/test/src_dir/brainfuck.bf @@ -0,0 +1,19 @@ +Print "Hello World!!!!!" + +Line that does nothing: >< +>++++++[>+++[<<++++>>-]<-]<. +>+++++[<++++++>-]<-. ++++++++. +. ++++. +>>++++[<++++++>-]<++[<--->-]<-. +>>++[<+++++>-]<+[<+++++>-]<. +>++++[<++++++>-]<. ++++. +------. +>++[<---->-]<. +>>++[<+++++>-]<+[<------>-]<-. +. +. +. +. diff --git a/test/src_dir/chaiscript.chai b/test/src_dir/chaiscript.chai new file mode 100644 index 0000000..208a933 --- /dev/null +++ b/test/src_dir/chaiscript.chai @@ -0,0 +1,17 @@ +/* +Random Comments +Foo Foo Foo +*/ +var submenu=1; +// comment +// another comment +submenu += 10 +var f = fun() { 5 }; +def myFun(i) : i > 0 { + return i + 10; +} + + +// some comment +var delay_hide=500 +b=0 diff --git a/test/src_dir/click_me.xaml b/test/src_dir/click_me.xaml new file mode 100644 index 0000000..7241415 --- /dev/null +++ b/test/src_dir/click_me.xaml @@ -0,0 +1,7 @@ + + + + diff --git a/test/src_dir/clj1.clj b/test/src_dir/clj1.clj new file mode 100644 index 0000000..4e6a9af --- /dev/null +++ b/test/src_dir/clj1.clj @@ -0,0 +1,16 @@ +;;; Copyright (C) 2009 Brendan Ribera. All rights reserved. +;;; Distributed under the MIT License; see the file LICENSE +;;; at the root of this distribution. +(ns kdtree) + +(defn dist-squared [a b] + "Compute the K-dimensional distance between two points" + (reduce + (for [i (range (count a))] + (let [v (- (nth a i) + (nth b i))] + (* v v))))) + +;;; Simple accessors +(defn- node-value [n] (first n)) +(defn- node-left [n] (first (rest n))) +(defn- node-right [n] (first (rest (rest n)))) diff --git a/test/src_dir/cmake1.cmake b/test/src_dir/cmake1.cmake new file mode 100644 index 0000000..b9eecd3 --- /dev/null +++ b/test/src_dir/cmake1.cmake @@ -0,0 +1,33 @@ +# blah comment +# + +something() +# comment +something_else() + +long_function( + # comment + param +) + +long_string(" + # looks like a comment but isn't +") + +long_string( + " + # looks like a comment but isn't + " +) + +message( + ' + # looks like a string but isn't + ' +) + +message("string") + +message( + +) diff --git a/test/src_dir/components.cu b/test/src_dir/components.cu new file mode 100644 index 0000000..e357e82 --- /dev/null +++ b/test/src_dir/components.cu @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include + +#include "components.h" +#include "common.h" + +#define THREADS 256 + +/* Store 3 RGB float components */ +__device__ void storeComponents(float *d_r, float *d_g, float *d_b, float r, float g, float b, int pos) +{ + d_r[pos] = (r/255.0f) - 0.5f; + d_g[pos] = (g/255.0f) - 0.5f; + d_b[pos] = (b/255.0f) - 0.5f; +} + +/* Store 3 RGB intege components */ +__device__ void storeComponents(int *d_r, int *d_g, int *d_b, int r, int g, int b, int pos) +{ + d_r[pos] = r - 128; + d_g[pos] = g - 128; + d_b[pos] = b - 128; +} diff --git a/test/src_dir/coq.v b/test/src_dir/coq.v new file mode 100644 index 0000000..37ae74c --- /dev/null +++ b/test/src_dir/coq.v @@ -0,0 +1,10 @@ +Require Import String. +(* comment *) +Check "multiline +string"%string. + +(* multiline + comment *) + +(* recursion in (* a + comment *) to complicate things *) diff --git a/test/src_dir/cs.aspx b/test/src_dir/cs.aspx new file mode 100644 index 0000000..b945fb2 --- /dev/null +++ b/test/src_dir/cs.aspx @@ -0,0 +1,29 @@ +<%@ Page Language="C#" %> + + + + Basic ASP.NET Web Page + + + <%if( ViewData["Message"] != null ){ %> +

<%=ViewData["Message"]%>


+ <% } %> +
+

Welcome to ASP.NET

+

Type your name and click the button.

+

+ + +

+

+ +

+
+ + diff --git a/test/src_dir/english.st b/test/src_dir/english.st new file mode 100644 index 0000000..205b8a0 --- /dev/null +++ b/test/src_dir/english.st @@ -0,0 +1,6 @@ +a +aa +aardvark +abacus +apple +zebra diff --git a/test/src_dir/example.R b/test/src_dir/example.R new file mode 100644 index 0000000..3740c46 --- /dev/null +++ b/test/src_dir/example.R @@ -0,0 +1,200 @@ +# Build a 'graph-like' object having 'nodes' nodes belonging to 'classes' classes. +# Class distribution is given by 'proba', and connectivity probabilities are given +# by 'intraproba' and 'interproba'. +generateGraph<-function(nodes,classes,proba=rep(1/classes,classes), + intraproba=0.1,crossproba=0.02) +{ + mat_pi=CreateConnectivityMat(classes,intraproba,crossproba) + igraph=Fast2SimuleERMG(nodes,proba,mat_pi[1],mat_pi[2]) + adjacency=get.adjacency(igraph$graph) + cmgraph=list(nodes=nodes,classes=classes,adjacency=adjacency,nodeclasses=igraph$node.classes,proba=proba, + intraproba=intraproba,crossproba=crossproba) + attr(cmgraph,'class')<-c('cmgraph') + cmgraph +} + +# Return explicit member names for the different attributes of graph objects. +labels.cmgraph<-function(object,...) +{ + c("Nodes","Classes","Adjacency Matrix","Node Classification","Class Probability Distribution","Intra Class Edge Probability","Cross Class Edge Probability") +} + +# Override the summmary function for graph objects. +summary.cmgraph<-function(object,...) +{ + + cat(c("Nodes : ",object$nodes,"\n", + "Edges : ",length(which(object$adjacency!=0)),"\n", + "Classes : ",object$classes,"\n", + "Class Probability Distribution: ",object$proba,"\n")) +} + +# Override the plot function for graph objects. +plot.cmgraph<-function(x,...) +{ + RepresentationXGroup(x$adjacency,x$nodeclasses) +} + +# Generate covariable data for the graph 'g'. Covariables are associated to vertex data, and +# their values are drawn according to 2 distributions: one for vertices joining nodes of +# the same class, and another for vertices joining nodes of different classes. +# The two distributions have different means but a single standard deviation. +generateCovariablesCondZ<-function(g,sameclustermean=0,otherclustermean=2,sigma=1) +{ + mu=CreateMu(g$classes,sameclustermean,otherclustermean) + res=SimDataYcondZ(g$nodeclasses,mu,sigma) + cmcovars=list(graph=g,sameclustermean=sameclustermean,otherclustermean=otherclustermean,sigma=sigma,mu=mu,y=res) + attr(cmcovars,'class')<-c('cmcovarz','cmcovar') + cmcovars +} + +# Generate covariable data for the graph 'g'. Covariables are associated to vertex data, and +# their values are drawn according to 2 distributions: one for vertices joining nodes of +# the same class, and another for vertices joining nodes of different classes. +# The two distributions have different means but a single standard deviation. +# This function generates two sets of covariables. +generateCovariablesCondXZ<-function(g,sameclustermean=c(0,3),otherclustermean=c(2,5),sigma=1) +{ + mux0=CreateMu(g$classes,sameclustermean[1],otherclustermean[1]) + mux1=CreateMu(g$classes,sameclustermean[2],otherclustermean[2]) + res=SimDataYcondXZ(g$nodeclasses,g$adjacency,mux0,mux1,sigma) + cmcovars=list(graph=g,sameclustermean=sameclustermean,otherclustermean=otherclustermean,sigma=sigma,mu=c(mux0,mux1),y=res) + attr(cmcovars,'class')<-c('cmcovarxz','cmcovar') + cmcovars +} + + +# Override the print function for a cleaner covariable output. +print.cmcovar<-function(x,...) +{ + cat("Classes : ",x$graph$classes,"\n", + "Intra cluster mean: ",x$sameclustermean,"\n", + "Cross cluster mean: ",x$otherclustermean,"\n", + "Variance : ",x$sigma,"\n", + "Covariables :\n",x$y,"\n") +} + + +# Perform parameter estimation on 'graph' given the covariables 'covars'. +estimateCondZ<-function(graph,covars,maxiterations,initialclasses,selfloops) +{ + res=EMalgorithm(initialclasses,covars$y,graph$adjacency,maxiterations,FALSE,selfloops) + cmestimation=list(mean=res$MuEstimated,variance=res$VarianceEstimated,pi=res$PIEstimated,alpha=res$AlphaEstimated,tau=res$TauEstimated,jexpected=res$EJ,graph=graph) + attr(cmestimation,'class')<-c('cmestimationz') + cmestimation +} + +# Private generic estimation function used to allow various call conventions for estimation functions. +privateestimate<-function(covars,graph,maxiterations,initialclasses,selfloops,...) UseMethod("privateestimate") + +# Private estimation function used to allow various call conventions for estimation functions. +# Override of generic function for single covariables. +privateestimate.cmcovarz<-function(covars,graph,maxiterations,initialclasses,selfloops,...) +{ + res=estimateCondZ(graph,covars,maxiterations,initialclasses,selfloops) + attr(res,'class')<-c(attr(res,'class'),'cmestimation') + res + +} + +# Perform parameter estimation on 'graph' given the covariables 'covars'. +estimateCondXZ<-function(graph,covars,maxiterations,initialclasses,selfloops) +{ + #resSimXZ = EMalgorithmXZ(TauIni,Y2,Adjacente,30,SelfLoop=FALSE) + res=EMalgorithmXZ(initialclasses,covars$y,graph$adjacency,maxiterations,selfloops) + cmestimation=list(mean=c(res$MuEstimated1,res$MuEstimated2),variance=res$VarianceEstimated,pi=res$PIEstimated,alpha=res$AlphaEstimated,tau=res$TauEstimated,jexpected=res$EJ,graph=graph) + attr(cmestimation,'class')<-c('cmestimationxz') + cmestimation +} + +# Private estimation function used to allow various call conventions for estimation functions. +# Override of generic function for multiple covariables. +privateestimate.cmcovarxz<-function(covars,graph,maxiterations,initialclasses,selfloops,...) +{ + res=estimateCondXZ(graph,covars,maxiterations,initialclasses,selfloops) + attr(res,'class')<-c(attr(res,'class'),'cmestimation') + res +} + +# Generic estimation function applicable to graphs with covariables. +estimate<-function(graph,covars,...) UseMethod("estimate") + +# Override of the generic estimation function. Performs the actual function dispatch depending on the class of covariables. +estimate.cmgraph<-function(graph,covars,maxiterations=20,initialclasses=t(rmultinom(size=1,prob=graph$proba,n=graph$nodes)),selfloops=FALSE,method=NULL,...) +{ + if (length(method) == 0) { + res=privateestimate(covars,graph,maxiterations,initialclasses,selfloops,...) + } else { + res=method(graph,covars,maxiterations,initialclasses,selfloops) + attr(res,'class')<-c(attr(res,'class'),'cmestimation') + } + res +} + +# Override of the generic pliot function for estimation results. +plot.cmestimation<-function(x,...) +{ + par(mfrow = c(1,2)) + plot(x$jexpected) + title("Expected value of J: Convergence criterion") + + map=MAP(x$tau) + gplot(x$graph$adjacency,vertex.col=map$node.classes+2) + title("Network with estimated classes") + +} + +# Generic private ICL computation function for graphs and covariables. +privatecomputeICL<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) UseMethod("privatecomputeICL") + + +# Private ICL computation function for graphs with single covariables. +privatecomputeICL.cmcovarz<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) +{ + res=ICL(X=graph$adjacency,Y=covars$y,Qmin=qmin,Qmax=qmax,loop=loops,NbIteration=maxiterations,SelfLoop=selfloops,Plot=FALSE) + attr(res,'class')<-c('cmiclz') + res + +} + +# Private ICL computation function for graphs with multiple covariables. +privatecomputeICL.cmcovarxz<-function(covars,graph,qmin,qmax,loops,maxiterations,selfloops) +{ + res=ICL(X=graph$adjacency,Y=covars$y,Qmin=qmin,Qmax=qmax,loop=loops,NbIteration=maxiterations,SelfLoop=selfloops,Plot=FALSE) + attr(res,'class')<-c('cmiclxz') + res +} + + +# Generic public ICL computation function applicable to graph objects. +computeICL<-function(graph,covars,qmin,qmax,...) UseMethod("computeICL") + +# Override of ICL computation function applicable to graph objects. +# Performs the actual method dispatch to private functions depending on the type of covariables. +computeICL.cmgraph<-function(graph,covars,qmin,qmax,loops=10,maxiterations=20,selfloops=FALSE,...) +{ + res=privatecomputeICL(covars,graph,qmin,qmax,loops,maxiterations,selfloops) + res$qmin=qmin + res$qmax=qmax + res$graph=graph + res$covars=covars + attr(res,'class')<-c(attr(res,'class'),'cmicl') + res +} + +# Override of the plot function for results of ICL computation. +plot.cmicl<-function(x,...) +{ + par(mfrow = c(1,2)) + result=x$iclvalues + maxi=which(max(result)==result) + plot(seq(x$qmin,x$qmax),result,type="b",xlab="Number of classes",ylab="ICL value") + points(maxi+x$qmin-1,result[maxi],col="red") + title("ICL curve") + best=x$EMestimation[[maxi+x$qmin-1]] + tau=best$TauEstimated + map=MAP(tau) + gplot(x$graph$adjacency,vertex.col=map$node.classes+2) + title("Network with estimated classes") +} + diff --git a/test/src_dir/example.qml b/test/src_dir/example.qml new file mode 100644 index 0000000..b92a82d --- /dev/null +++ b/test/src_dir/example.qml @@ -0,0 +1,17 @@ +// Just an example of QML file... + +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 200 + color: "crimson" + + MouseArea { + anchors.fill: parent + onClicked: { + // Was clicked + Qt.quit(); + } + } +} diff --git a/test/src_dir/example.rkt b/test/src_dir/example.rkt new file mode 100644 index 0000000..502b961 --- /dev/null +++ b/test/src_dir/example.rkt @@ -0,0 +1,12 @@ +;; language declaration commented out until someone extends the +;; parser to support it: + +;; #lang racket + +;; Report each unique line from stdin +(let ([saw (make-hash)]) + (for ([line (in-lines)]) + (unless (hash-ref saw line #f) + (displayln line)) + (hash-set! saw line #t))) + diff --git a/test/src_dir/fb.js b/test/src_dir/fb.js new file mode 100644 index 0000000..f71c201 --- /dev/null +++ b/test/src_dir/fb.js @@ -0,0 +1,9 @@ +function escapeHTML(value) +{ + return String(value).replace(/[<>&"']/g, replaceChars); +} + +window.onerror = onError; + +if (document.documentElement.getAttribute("debug") == "true") + toggleConsole(true); diff --git a/test/src_dir/foo.coffee b/test/src_dir/foo.coffee new file mode 100644 index 0000000..aa0f216 --- /dev/null +++ b/test/src_dir/foo.coffee @@ -0,0 +1,26 @@ +# A CoffeeScript parser test file + +simple_code = true + +### +A multi-line block comment +begins and ends with three hash marks +### + +multi_line_string = ''' + A multi-line string constant ("here doc") + begins and ends with three quote marks + ''' + +foo = "A string can wrap across multiple lines + and may contain #{interpolated_values}" + + +### +A clever parser can use Ohcount's "Polyglot" feature treat the +following as embedded JavaScript. +### +embedded_js = `function() { + return [document.title, "Hello JavaScript"].join(": "); +}` + diff --git a/test/src_dir/foo.dtx b/test/src_dir/foo.dtx new file mode 100644 index 0000000..d8cb14d --- /dev/null +++ b/test/src_dir/foo.dtx @@ -0,0 +1,9 @@ +\begin{document} +\texbf Hello world + + +% \acommand +% \anothercommand +%% sample comment + +\end{document} diff --git a/test/src_dir/foo.glsl b/test/src_dir/foo.glsl new file mode 100644 index 0000000..e134a61 --- /dev/null +++ b/test/src_dir/foo.glsl @@ -0,0 +1,4 @@ +// GLSL vertex shader +void main() { + gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; +} \ No newline at end of file diff --git a/test/src_dir/foo.nsh b/test/src_dir/foo.nsh new file mode 100644 index 0000000..8638e86 --- /dev/null +++ b/test/src_dir/foo.nsh @@ -0,0 +1,17 @@ +; NSIS "header" libraries can be in .nsh files. +/* Copyright some time + * never + * and not much of that either +"still a comment" +*/ + +!macro SillyMacro Param1 + ; ... Because we can ;-) + !error "Why did you call this macro, ${Param1}? That was silly." +!macroend + +Function Die + # Likewise, because we can. + DetailPrint "Aarrrrggghh! I died." + Quit +FunctionEnd diff --git a/test/src_dir/foo.nsi b/test/src_dir/foo.nsi new file mode 100644 index 0000000..84ebfd8 --- /dev/null +++ b/test/src_dir/foo.nsi @@ -0,0 +1,15 @@ +; some nsis code +/* + * lorem +ipsum +dolor sit amet etcetera +*/ + +!include LogicLib.nsh +OutFile foo.exe + +Section + IfFileExists ${__FILE__} 0 +2 ; comments can be inline + # Use of ; in a string on the next line + MessageBox MB_OK "You moved this installer file; you shouldn't do that ;-)" +SectionEnd diff --git a/test/src_dir/foo_glsl.vert b/test/src_dir/foo_glsl.vert new file mode 100644 index 0000000..4f2d4fc --- /dev/null +++ b/test/src_dir/foo_glsl.vert @@ -0,0 +1,43 @@ +// from OGRE3D's skinningTwoWeightsShadowCasterVp.glsl +// Example GLSL program for skinning with two bone weights per vertex + +attribute vec4 vertex; +attribute vec4 uv0; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +// 3x4 matrix, passed as vec4's for compatibility with GL 2.0 +// GL 2.0 supports 3x4 matrices +// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +uniform vec4 worldMatrix3x4Array[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 ambient; + +void main() +{ + vec3 blendPos = vec3(0,0,0); + + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first + int idx = int(blendIndices[bone]) * 3; + // ATI GLSL compiler can't handle unrolling the loop so do it manually + // ATI GLSL has better performance when mat4 is used rather than using individual dot product + // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign + mat4 worldMatrix; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4(0); + // now weight this into final + blendPos += (vertex * worldMatrix).xyz * blendWeights[bone]; + } + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1); + + gl_FrontSecondaryColor = vec4(0,0,0,0); + gl_FrontColor = ambient; + gl_TexCoord[0] = uv0; +} diff --git a/test/src_dir/forth.4th b/test/src_dir/forth.4th new file mode 100644 index 0000000..75ce18d --- /dev/null +++ b/test/src_dir/forth.4th @@ -0,0 +1,7 @@ +\ Sample Forth code + +( This is a comment + spanning multiple lines ) + +: somedefinition ; + diff --git a/test/src_dir/fs1.fs b/test/src_dir/fs1.fs new file mode 100644 index 0000000..433670d --- /dev/null +++ b/test/src_dir/fs1.fs @@ -0,0 +1,51 @@ +(*************************************************************************** + * + * The Parser is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + ***************************************************************************) + +namespace Tags + +open System +open System.Reflection; +open System.Runtime.CompilerServices; +open System.Runtime.InteropServices; + +module internal Filter = + + let FILTER_VARIABLE_NAME = "$filter" + + type FilterNode(provider, token, filter: FilterExpression, node_list) = + inherit TagNode(provider, token) + + override this.walk manager walker = + let reader = + new NDjango.ASTWalker.Reader (manager, {walker with parent=None; nodes=node_list; context=walker.context}) + match filter.ResolveForOutput manager + {walker with context=walker.context.add(FILTER_VARIABLE_NAME, (reader.ReadToEnd():>obj))} + with + | Some w -> w + | None -> walker + + /// Filters the contents of the block through variable filters. + /// + /// Filters can also be piped through each other, and they can have + /// arguments -- just like in variable syntax. + /// + /// Sample usage:: + /// + /// {% filter force_escape|lower %} + /// This text will be HTML-escaped, and will appear in lowercase. + /// {% endfilter %} + type FilterTag() = + interface ITag with + member this.Perform token provider tokens = + match token.Args with + | filter::[] -> + let filter_expr = new FilterExpression(provider, Block token, FILTER_VARIABLE_NAME + "|" + filter) + let node_list, remaining = (provider :?> IParser).Parse (Some token) tokens ["endfilter"] + (new FilterNode(provider, token, filter_expr, node_list) :> INodeImpl), remaining + | _ -> raise (SyntaxError ("'filter' tag requires one argument")) diff --git a/test/src_dir/grace.grace b/test/src_dir/grace.grace new file mode 100644 index 0000000..3343b9a --- /dev/null +++ b/test/src_dir/grace.grace @@ -0,0 +1,46 @@ +////////////////////////////////////////////////// +// Sample Grace code + +import "parsers-test" as parsers + +class exports { + inherit parsers.exports + //BEGINGRAMMAR + // top level + def program = rule {codeSequence ~ rep(ws) ~ end} + def codeSequence = rule { repdel((declaration | statement | empty), semicolon) } + def hashLine = rule { (symbol "#") ~ rep(anyChar | space) ~ (newLine | end) } + + // def comment = + + //def oldClassDeclaration = rule { classId ~ identifier ~ lBrace ~ + // opt(genericFormals ~ blockFormals ~ arrow) ~ codeSequence ~ rBrace } + + def typeOpExpression = rule { rep1sep(basicTypeExpression, typeOp) } + + def typeOpExpression = rule { + var otherOperator + basicTypeExpression ~ opt(ws) ~ + opt( guard(typeOp, { s -> otherOperator:= s; + true }) ~ rep1sep(basicTypeExpression ~ opt(ws), + guard(typeOp, { s -> s == otherOperator }) + ) + ) + } + + // "literals" + def literal = rule { stringLiteral | selfLiteral | blockLiteral | numberLiteral | objectLiteral | lineupLiteral | typeLiteral } + + // terminals + def backslash = token "\\" // doesn't belong here, doesn't work if left below! + + def colon = rule {both(symbol ":", not(assign))} + def newLine = symbol "\n" + def lParen = symbol "(" + def rParen = symbol ")" + + def reservedOp = rule {assign | equals | dot | arrow | colon | semicolon} // this is not quite right + + //ENDGRAMMAR +} + diff --git a/test/src_dir/haxe1.hx b/test/src_dir/haxe1.hx new file mode 100644 index 0000000..d8292c0 --- /dev/null +++ b/test/src_dir/haxe1.hx @@ -0,0 +1,101 @@ +/* +# ***** BEGIN LICENSE BLOCK ***** +Copyright the original author or authors. +Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.mozilla.org/MPL/MPL-1.1.html +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +# ***** END LICENSE BLOCK ***** +*/ + +package sandy.parser; + +/** + * The Parser factory class creates instances of parser classes. + * The specific parser can be specified in the create method's second parameter. + * + * @author Thomas Pfeiffer - kiroukou + * @author Niel Drummond - haXe port + * + * + * + * @example To parse a 3DS file at runtime: + * + * + * var parser:IParser = Parser.create( "/path/to/my/3dsfile.3ds", Parser.max ); + * + * + */ + +class Parser +{ + /** + * Parameter that is used to specify that the ASE (ASCII Scene Export) + * Parser should be used + */ + public static var ASE:String = "ASE"; + /** + * Parameter that is used to specify that the 3DS (3D Studio) Parser + * should be used + */ + public static var MAX_3DS:String = "3DS"; + /** + * Parameter that is used to specify that the COLLADA (COLLAborative + * Design Activity ) Parser should be used + */ + public static var COLLADA:String = "DAE"; + + /** + * The create method chooses which parser to use. This can be done automatically + * by looking at the file extension or by passing the parser type String as the + * second parameter. + * + * @example To parse a 3DS file at runtime: + * + * + * var parser:IParser = Parser.create( "/path/to/my/3dsfile.3ds", Parser.MAX ); + * + * + * @param p_sFile Can be either a string pointing to the location of the + * file or an instance of an embedded file + * @param p_sParserType The parser type string + * @param p_nScale The scale factor + * @return The parser to be used + */ + public static function create( p_sFile:Dynamic, ?p_sParserType:String, ?p_nScale:Float ):IParser + { + if ( p_nScale == null ) p_nScale = 1; + + var l_sExt:String,l_iParser:IParser = null; + // -- + if( Std.is( p_sFile, String ) && p_sParserType == null ) + { + l_sExt = (p_sFile.split('.')).reverse()[0]; + } + else + { + l_sExt = p_sParserType; + } + // -- + switch( l_sExt.toUpperCase() ) + { + case "ASE": + l_iParser = new ASEParser( p_sFile, p_nScale ); + case "OBJ": + case "DAE": + l_iParser = new ColladaParser( p_sFile, p_nScale ); + case "3DS": + l_iParser = new Parser3DS( p_sFile, p_nScale ); + default: + } + // -- + return l_iParser; + } +} + diff --git a/test/src_dir/perl.cgi b/test/src_dir/html.cgi similarity index 100% rename from test/src_dir/perl.cgi rename to test/src_dir/html.cgi diff --git a/test/src_dir/idl_pvwave.pro b/test/src_dir/idl_pvwave.pro new file mode 100644 index 0000000..f797c91 --- /dev/null +++ b/test/src_dir/idl_pvwave.pro @@ -0,0 +1,83 @@ +;+ +; NAME: +; SHOWFONT +; +; PURPOSE: +; Uses current graphics device to draw a map of characters +; available in the font specified in argument +; +; CATEGORY: +; General +; +; CALLING SEQUENCE: +; showfont, num, 'title' ; table of font num entitled 'title' +; +; KEYWORD PARAMETERS: +; /encapsulated ; ignored (just for compatibility) +; /tt_font ; ignored (just for compatibility) +; base = 16 ; number of columns in the table +; beg = 32 ; first character +; fin = num eq 3 ? 255 : 127 ; last character +; +; OUTPUTS: +; None. +; +; OPTIONAL OUTPUTS: +; None. +; +; COMMON BLOCKS: +; None. +; +; SIDE EFFECTS: +; Draws a font table on the current graphic device. +; +; RESTRICTIONS: +; None. +; +; PROCEDURE: +; +; EXAMPLE: +; showfont, 9, 'GDL math symbols' ; show mappings for font 9 +; +; MODIFICATION HISTORY: +; Written by: Sylwester Arabas (2008/12/28) +;- +; LICENCE: +; Copyright (C) 2008, +; This program is free software; you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation; either version 2 of the License, or +; (at your option) any later version. +;- + +pro showfont, num, name, encapsulated=eps, tt_font=tt, base=base, beg=beg, fin=fin + + ; handling default keyword values + if not keyword_set(base) then base = 16 + if not keyword_set(beg) then beg = 32 + if not keyword_set(fin) then fin = num eq 3 ? 255 : 127 + if not keyword_set(name) then name = '' + + ; constructing horizontal and vertical grid lines + n_hor = (fin + 1 - beg) / base + 1 + h_x = (double(rebin(base * byte(128 * indgen(2 * (n_hor))) / 128, 4 * n_hor, /sample)))[1:4 * n_hor - 1] - .5 + h_y = (double(rebin(beg + indgen(n_hor) * base, 4 * n_hor, /sample)))[0:4 * n_hor - 2] - base/2. + v_x = base - indgen(4 * base - 1) / 4 - .5 + v_y = (double(rebin(byte(128 * indgen(2 * (base))) / 128, 4 * base, /sample)))[1:4 * base - 1] $ + * base * ((fin + 1 - beg) / base) + beg - base / 2. + + ; ploting grid and title + plot, [h_x, v_x], [h_y, v_y], $ + title='Font ' + strtrim(string(num), 2) + ', ' + name, $ + xrange=[-1, base], $ + yrange=[base * ((fin + 1) / base), beg - base], $ + yticks=n_hor, $ + xticks=base+1, $ + xtitle='char mod ' + strtrim(string(base), 2), $ + ytitle=strtrim(string(base), 2) + ' * (char / ' + strtrim(string(base), 2) + ')' + + ; ploting characters + for c = beg, fin do $ + xyouts, (c mod base), base * (c / base), '!' + strtrim(string(num), 2) + string(byte(c)) + +end diff --git a/test/src_dir/limbo.b b/test/src_dir/limbo.b new file mode 100644 index 0000000..ad49168 --- /dev/null +++ b/test/src_dir/limbo.b @@ -0,0 +1,65 @@ +implement HgReadrevlog; + +include "sys.m"; + sys: Sys; + sprint: import sys; +include "draw.m"; +include "arg.m"; +include "string.m"; + str: String; +include "mercurial.m"; + mercurial: Mercurial; + Revlog, Repo, Entry, Nodeid, Change: import mercurial; + +dflag: int; + +HgReadrevlog: module { + init: fn(nil: ref Draw->Context, args: list of string); +}; + +init(nil: ref Draw->Context, args: list of string) +{ + sys = load Sys Sys->PATH; + arg := load Arg Arg->PATH; + str = load String String->PATH; + mercurial = load Mercurial Mercurial->PATH; + mercurial->init(); + + arg->init(args); + arg->setusage(arg->progname()+" [-d] path"); + while((c := arg->opt()) != 0) + case c { + 'd' => dflag++; + if(dflag > 1) + mercurial->debug++; + * => arg->usage(); + } + args = arg->argv(); + if(len args != 1) + arg->usage(); + path := hd args; + + (rl, err) := Revlog.open(path); + if(err != nil) + fail(err); + + last: int; + (last, err) = rl.lastrev(); + if(err != nil) + fail(err); + + e: ref Entry; + for(i := 0; i <= last; i++) { + (e, err) = rl.findrev(i); + if(err != nil) + fail(err); + #sys->print("entry %d:\n", i); + sys->print("%s\n", e.text()); + } +} + +fail(s: string) +{ + sys->fprint(sys->fildes(2), "%s\n", s); + raise "fail:"+s; +} diff --git a/test/src_dir/limbo.m b/test/src_dir/limbo.m new file mode 100644 index 0000000..fcd10ff --- /dev/null +++ b/test/src_dir/limbo.m @@ -0,0 +1,8 @@ +Htmlent: module { + PATH: con "/dis/lib/htmlent.dis"; + entities: array of (string, int); + + init: fn(); + lookup: fn(name: string): int; + conv: fn(s: string): string; +}; diff --git a/test/src_dir/logtalk.lgt b/test/src_dir/logtalk.lgt new file mode 100644 index 0000000..e65124b --- /dev/null +++ b/test/src_dir/logtalk.lgt @@ -0,0 +1,11 @@ +/* test file for Logtalk parsing */ + +% this is a Logtalk source file + +:- object(hello_world). + + % the initialization/1 directive argument is automatically executed + % when the object is loaded into memory: + :- initialization((nl, write('********** Hello World! **********'), nl)). + +:- end_object. diff --git a/test/src_dir/mathematica1.m b/test/src_dir/mathematica1.m new file mode 100644 index 0000000..6cccde6 --- /dev/null +++ b/test/src_dir/mathematica1.m @@ -0,0 +1,1480 @@ + +SetEnhancedTimes[False]; +SetSourceLanguage["C"]; + +(******************************************************************************) +(* Options *) +(******************************************************************************) + +createCode[derivOrder_, useJacobian_, splitUpwindDerivs_, useVectors_, useOpenCL_, evolutionTimelevels_, addMatter_, formulation_] := +Module[{prefix, suffix, thorn}, + +prefix = "ML_"; +suffix = + "" + <> If [useJacobian, "_MP", ""] + <> If [derivOrder!=4, "_O" <> ToString[derivOrder], ""] + <> If [splitUpwindDerivs, "", "_UPW"] + <> If [useVectors, "", "_NV"] + <> If [useOpenCL, "_CL", ""] + (* <> If [evolutionTimelevels!=3, "_TL" <> ToString[evolutionTimelevels], ""] *) + (* <> If [addMatter==1, "_M", ""] *) + ; + +thorn = prefix <> formulation <> suffix; + +SetAttributes[IfCCZ4, HoldAll]; +IfCCZ4[expr_, else_:Sequence[]] := If[formulation === "CCZ4", expr, Unevaluated[else]]; + +(******************************************************************************) +(* Derivatives *) +(******************************************************************************) + +KD = KroneckerDelta; + +derivatives = +{ + PDstandardNth[i_] -> StandardCenteredDifferenceOperator[1,fdOrder/2,i], + PDstandardNth[i_,i_] -> StandardCenteredDifferenceOperator[2,fdOrder/2,i], + PDstandardNth[i_,j_] -> StandardCenteredDifferenceOperator[1,fdOrder/2,i] * + StandardCenteredDifferenceOperator[1,fdOrder/2,j], + PDdissipationNth[i_] -> + (-1)^(fdOrder/2) * + spacing[i]^(fdOrder+1) / 2^(fdOrder+2) * + StandardCenteredDifferenceOperator[fdOrder+2,fdOrder/2+1,i], + +(* PD: These come from my mathematica notebook + "Upwind-Kranc-Convert.nb" that converts upwinding finite + differencing operators generated by + StandardUpwindDifferenceOperator into this form *) + + Sequence@@Flatten[Table[ + {PDupwindNth[i] -> Switch[fdOrder, + 2, (dir[i]*(-3 + 4*shift[i]^dir[i] - shift[i]^(2*dir[i])))/(2*spacing[i]), + 4, (dir[i]*(-10 - 3/shift[i]^dir[i] + 18*shift[i]^dir[i] - + 6*shift[i]^(2*dir[i]) + shift[i]^(3*dir[i])))/(12*spacing[i]), + 6, (dir[i]*(-35 + 2/shift[i]^(2*dir[i]) - 24/shift[i]^dir[i] + 80*shift[i]^dir[i] - + 30*shift[i]^(2*dir[i]) + 8*shift[i]^(3*dir[i]) - shift[i]^(4*dir[i])))/(60*spacing[i]), + 8, (dir[i]*(-378 - 5/shift[i]^(3*dir[i]) + 60/shift[i]^(2*dir[i]) - 420/shift[i]^dir[i] + + 1050*shift[i]^dir[i] - 420*shift[i]^(2*dir[i]) + 140*shift[i]^(3*dir[i]) - 30*shift[i]^(4*dir[i]) + + 3*shift[i]^(5*dir[i])))/(840*spacing[i])], + + PDupwindNthAnti[i] -> Switch[fdOrder, + 2, (+1 shift[i]^(-2) -4 shift[i]^(-1) +0 shift[i]^( 0) +4 shift[i]^(+1) -1 shift[i]^(+2)) / (4 spacing[i]), + 4, (-1 shift[i]^(-3) +6 shift[i]^(-2) -21 shift[i]^(-1 )+0 shift[i]^( 0) +21 shift[i]^(+1) + -6 shift[i]^(+2) +1 shift[i]^(+3)) / (24 spacing[i]), + 6, (+1 shift[i]^(-4) -8 shift[i]^(-3) +32 shift[i]^(-2) -104 shift[i]^(-1) +0 shift[i]^( 0) + +104 shift[i]^(+1) -32 shift[i]^(+2) +8 shift[i]^(+3) -1 shift[i]^(+4)) / (120 spacing[i]), + 8, (-3 shift[i]^(-5) +30 shift[i]^(-4) -145 shift[i]^(-3) +480 shift[i]^(-2) -1470 shift[i]^(-1) + +0 shift[i]^( 0) +1470 shift[i]^(+1) -480 shift[i]^(+2) +145 shift[i]^(+3) -30 shift[i]^(+4) + +3 shift[i]^(+5)) / (1680 spacing[i])], + + PDupwindNthSymm[i] -> Switch[fdOrder, + 2, (-1 shift[i]^(-2) +4 shift[i]^(-1) -6 shift[i]^( 0) +4 shift[i]^(+1) -1 shift[i]^(+2)) / (4 spacing[i]), + 4, (+1 shift[i]^(-3) -6 shift[i]^(-2) +15 shift[i]^(-1) -20 shift[i]^( 0) +15 shift[i]^(+1) + -6 shift[i]^(+2) +1 shift[i]^(+3)) / (24 spacing[i]), + 6, (-1 shift[i]^(-4) +8 shift[i]^(-3) - 28 shift[i]^(-2)+56 shift[i]^(-1)-70 shift[i]^( 0) + +56 shift[i]^(+1) -28 shift[i]^(+2) +8 shift[i]^(+3) -1 shift[i]^(+4)) / (120 spacing[i]), + 8, (+3 shift[i]^(-5) -30 shift[i]^(-4) +135 shift[i]^(-3) -360 shift[i]^(-2) +630 shift[i]^(-1) + -756 shift[i]^( 0) +630 shift[i]^(+1) -360 shift[i]^(+2) +135 shift[i]^(+3) -30 shift[i]^(+4) + +3 shift[i]^(+5)) / (1680 spacing[i])], + + (* TODO: make these higher order stencils *) + PDonesided[i] -> dir[i] (-1 + shift[i]^dir[i]) / spacing[i]} /. i->j, {j,1,3}],1] +}; + +PD = PDstandardNth; +PDu = PDupwindNth; +PDua = PDupwindNthAnti; +PDus = PDupwindNthSymm; +(* PDo = PDonesided; *) +PDdiss = PDdissipationNth; + +If [splitUpwindDerivs, + Upwind[dir_, var_, idx_] := dir PDua[var,idx] + Abs[dir] PDus[var,idx], + Upwind[dir_, var_, idx_] := dir PDu[var,idx]]; + + + +(******************************************************************************) +(* Tensors *) +(******************************************************************************) + +(* Register the tensor quantities with the TensorTools package *) +Map [DefineTensor, + {normal, tangentA, tangentB, dir, + nn, nu, nlen, nlen2, su, vg, + xx, rr, th, ph, + admg, admK, admalpha, admdtalpha, admbeta, admdtbeta, H, M, + g, detg, gu, G, R, trR, Km, trK, cdphi, cdphi2, + phi, gt, At, Xt, Xtn, Theta, Z, + alpha, A, beta, B, Atm, Atu, trA, Ats, trAts, + dottrK, dotXt, + cXt, cS, cA, + e4phi, em4phi, ddetg, detgt, gtu, ddetgt, dgtu, ddgtu, Gtl, Gtlu, Gt, + Rt, Rphi, gK, + T00, T0, T, rho, S, + x, y, z, r, + epsdiss}]; + +(* NOTE: It seems as if Lie[.,.] did not take these tensor weights + into account. Presumably, CD[.,.] and CDt[.,.] don't do this either. *) +SetTensorAttribute[phi, TensorWeight, +1/6]; +SetTensorAttribute[gt, TensorWeight, -2/3]; +SetTensorAttribute[Xt, TensorWeight, +2/3]; +SetTensorAttribute[At, TensorWeight, -2/3]; +SetTensorAttribute[cXt, TensorWeight, +2/3]; +SetTensorAttribute[cS, TensorWeight, +2 ]; + +Map [AssertSymmetricIncreasing, + {admg[la,lb], admK[la,lb], g[la,lb], K[la,lb], R[la,lb], cdphi2[la,lb], + gt[la,lb], At[la,lb], Ats[la,lb], Rt[la,lb], Rphi[la,lb], T[la,lb]}]; +AssertSymmetricIncreasing [G[ua,lb,lc], lb, lc]; +AssertSymmetricIncreasing [Gtl[la,lb,lc], lb, lc]; +AssertSymmetricIncreasing [Gt[ua,lb,lc], lb, lc]; +AssertSymmetricIncreasing [gK[la,lb,lc], la, lb]; +Map [AssertSymmetricIncreasing, + {gu[ua,ub], gtu[ua,ub], Atu[ua,ub]}]; +AssertSymmetricIncreasing [dgtu[ua,ub,lc], ua, ub]; +AssertSymmetricIncreasing [ddgtu[ua,ub,lc,ld], ua, ub]; +AssertSymmetricIncreasing [ddgtu[ua,ub,lc,ld], lc, ld]; + +DefineConnection [CD, PD, G]; +DefineConnection [CDt, PD, Gt]; + +(* Use the CartGrid3D variable names *) +x1=x; x2=y; x3=z; + +(* Use the ADMBase variable names *) +admg11=gxx; admg12=gxy; admg22=gyy; admg13=gxz; admg23=gyz; admg33=gzz; +admK11=kxx; admK12=kxy; admK22=kyy; admK13=kxz; admK23=kyz; admK33=kzz; +admalpha=alp; +admdtalpha=dtalp; +admbeta1=betax; admbeta2=betay; admbeta3=betaz; +admdtbeta1=dtbetax; admdtbeta2=dtbetay; admdtbeta3=dtbetaz; + +(* Use the TmunuBase variable names *) +T00=eTtt; +T01=eTtx; T02=eTty; T03=eTtz; +T11=eTxx; T12=eTxy; T22=eTyy; T13=eTxz; T23=eTyz; T33=eTzz; + + + +(******************************************************************************) +(* Expressions *) +(******************************************************************************) + +(* enum constants for conformalMethod; these must be consistent + with the definition of the Cactus parameter conformalMethod *) +CMphi = 0; +CMW = 1; + +detgExpr = Det [MatrixOfComponents [g [la,lb]]]; +ddetgExpr[la_] = + Sum [D[Det[MatrixOfComponents[g[la, lb]]], X] PD[X, la], + {X, Union[Flatten[MatrixOfComponents[g[la, lb]]]]}]; + +detgtExpr = Det [MatrixOfComponents [gt[la,lb]]]; +ddetgtExpr[la_] = + Sum [D[Det[MatrixOfComponents[gt[la, lb]]], X] PD[X, la], + {X, Union[Flatten[MatrixOfComponents[gt[la, lb]]]]}]; + +etaExpr = SpatialBetaDriverRadius / Max [r, SpatialBetaDriverRadius]; +thetaExpr = Min [Exp [1 - r / SpatialShiftGammaCoeffRadius], 1]; + + + +(******************************************************************************) +(* Groups *) +(******************************************************************************) + +evolvedGroups = + {SetGroupName [CreateGroupFromTensor [phi ], prefix <> "log_confac"], + SetGroupName [CreateGroupFromTensor [gt[la,lb]], prefix <> "metric" ], + SetGroupName [CreateGroupFromTensor [Xt[ua] ], prefix <> "Gamma" ], + SetGroupName [CreateGroupFromTensor [trK ], prefix <> "trace_curv"], + SetGroupName [CreateGroupFromTensor [At[la,lb]], prefix <> "curv" ], + SetGroupName [CreateGroupFromTensor [alpha ], prefix <> "lapse" ], + SetGroupName [CreateGroupFromTensor [A ], prefix <> "dtlapse" ], + SetGroupName [CreateGroupFromTensor [beta[ua] ], prefix <> "shift" ], + SetGroupName [CreateGroupFromTensor [B[ua] ], prefix <> "dtshift" ], + IfCCZ4[SetGroupName[CreateGroupFromTensor[Theta], prefix <> "Theta"]]}; +evaluatedGroups = + {SetGroupName [CreateGroupFromTensor [H ], prefix <> "Ham"], + SetGroupName [CreateGroupFromTensor [M[la] ], prefix <> "mom"], + SetGroupName [CreateGroupFromTensor [cS ], prefix <> "cons_detg"], + SetGroupName [CreateGroupFromTensor [cXt[ua]], prefix <> "cons_Gamma"], + SetGroupName [CreateGroupFromTensor [cA ], prefix <> "cons_traceA"]}; + +declaredGroups = Join [evolvedGroups, evaluatedGroups]; +declaredGroupNames = Map [First, declaredGroups]; + + + +extraGroups = + {{"grid::coordinates", {x, y, z, r}}, + {"ADMBase::metric", {gxx, gxy, gxz, gyy, gyz, gzz}}, + {"ADMBase::curv", {kxx, kxy, kxz, kyy, kyz, kzz}}, + {"ADMBase::lapse", {alp}}, + {"ADMBase::dtlapse", {dtalp}}, + {"ADMBase::shift", {betax, betay, betaz}}, + {"ADMBase::dtshift", {dtbetax, dtbetay, dtbetaz}}, + {"TmunuBase::stress_energy_scalar", {eTtt}}, + {"TmunuBase::stress_energy_vector", {eTtx, eTty, eTtz}}, + {"TmunuBase::stress_energy_tensor", {eTxx, eTxy, eTxz, eTyy, eTyz, eTzz}} +}; + +groups = Join [declaredGroups, extraGroups]; + + + +(******************************************************************************) +(* Initial data *) +(******************************************************************************) + +initialCalc = +{ + Name -> thorn <> "_Minkowski", + Schedule -> {"IN ADMBase_InitialData"}, + ConditionalOnKeyword -> {"my_initial_data", "Minkowski"}, + Equations -> + { + phi -> IfThen[conformalMethod==CMW, 1, 0], + gt[la,lb] -> KD[la,lb], + trK -> 0, + At[la,lb] -> 0, + Xt[ua] -> 0, + alpha -> 1, + A -> 0, + beta[ua] -> 0, + B[ua] -> 0, + IfCCZ4[Theta -> 0] + } +}; + + + +(******************************************************************************) +(* Split a calculation *) +(******************************************************************************) + +PartialCalculation[calc_, suffix_, updates_, evolVars_] := +Module[ + {name, calc1, replaces, calc2, vars, patterns, eqs, calc3}, + (* Add suffix to name *) + name = lookup[calc, Name] <> suffix; + calc1 = mapReplace[calc, Name, name]; + (* Replace some entries in the calculation *) + (* replaces = Map[Function[rule, mapReplace[#, rule[[1]], rule[[2]]]&], updates]; *) + replaces = updates //. (lhs_ -> rhs_) -> (mapReplace[#, lhs, rhs]&); + calc2 = Apply[Composition, replaces][calc1]; + (* Remove unnecessary equations *) + vars = Join[evolVars, lookup[calc2, Shorthands]]; + patterns = Replace[vars, { Tensor[n_,__] -> Tensor[n,__] , + dot[Tensor[n_,__]] -> dot[Tensor[n,__]]}, 1]; + eqs = FilterRules[lookup[calc, Equations], patterns]; + calc3 = mapReplace[calc2, Equations, eqs]; + calc3 +]; + + + +(******************************************************************************) +(* Convert from ADMBase *) +(******************************************************************************) + +convertFromADMBaseCalc = +{ + Name -> thorn <> "_convertFromADMBase", + Schedule -> {"AT initial AFTER ADMBase_PostInitial"}, + ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, + Shorthands -> {g[la,lb], detg, gu[ua,ub], em4phi}, + Equations -> + { + g[la,lb] -> admg[la,lb], + detg -> detgExpr, + gu[ua,ub] -> 1/detg detgExpr MatrixInverse [g[ua,ub]], + + phi -> IfThen[conformalMethod==CMW, detg^(-1/6), Log[detg]/12], + em4phi -> IfThen[conformalMethod==CMW, phi^2, Exp[-4 phi]], + gt[la,lb] -> em4phi g[la,lb], + + trK -> gu[ua,ub] admK[la,lb], + At[la,lb] -> em4phi (admK[la,lb] - (1/3) g[la,lb] trK), + + alpha -> admalpha, + + beta[ua] -> admbeta[ua], + + IfCCZ4[Theta -> 0] + } +}; + +convertFromADMBaseGammaCalc = +{ + Name -> thorn <> "_convertFromADMBaseGamma", + Schedule -> {"AT initial AFTER " <> thorn <> "_convertFromADMBase"}, + ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, + (* + Where -> InteriorNoSync, + *) + (* Do not synchronise right after this routine; instead, synchronise + after extrapolating *) + Where -> Interior, + (* Synchronise after this routine, so that the refinement boundaries + are set correctly before extrapolating. (We will need to + synchronise again after extrapolating because extrapolation does + not fill ghost zones, but this is irrelevant here.) *) + Shorthands -> {dir[ua], + detgt, gtu[ua,ub], Gt[ua,lb,lc], theta}, + Equations -> + { + dir[ua] -> Sign[beta[ua]], + + detgt -> 1 (* detgtExpr *), + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + Gt[ua,lb,lc] -> 1/2 gtu[ua,ud] + (PD[gt[lb,ld],lc] + PD[gt[lc,ld],lb] - PD[gt[lb,lc],ld]), + Xt[ua] -> gtu[ub,uc] Gt[ua,lb,lc], + +(* + A -> - admdtalpha / (harmonicF alpha^harmonicN) (LapseAdvectionCoeff - 1), +*) + (* If LapseACoeff=0, then A is not evolved, in the sense that it + does not influence the time evolution of other variables. *) + A -> IfThen [LapseACoeff != 0, + 1 / (- harmonicF alpha^harmonicN) + (+ admdtalpha + - LapseAdvectionCoeff Upwind[beta[ua], alpha, la]), + 0], + + theta -> thetaExpr, + + (* If ShiftBCoeff=0 or theta ShiftGammaCoeff=0, then B^i is not + evolved, in the sense that it does not influence the time + evolution of other variables. *) + B[ua] -> IfThen [ShiftGammaCoeff ShiftBCoeff != 0, + 1 / (theta ShiftGammaCoeff) + (+ admdtbeta[ua] + - ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb]), + 0] + } +}; + +(* Initialise the Gamma variables to 0. This is necessary with + multipatch because convertFromADMBaseGamma does not perform the + conversion in the boundary points, and the order in which symmetry + (interpatch) and outer boundary conditions is applied means that + points which are both interpatch and symmetry points are never + initialised. *) +initGammaCalc = +{ + Name -> thorn <> "_InitGamma", + Schedule -> {"AT initial BEFORE " <> thorn <> "_convertFromADMBaseGamma"}, + ConditionalOnKeyword -> {"my_initial_data", "ADMBase"}, + Where -> Everywhere, + Equations -> + { + Xt[ua] -> 0, + A -> 0, + B[ua] -> 0 + } +}; + + + +(******************************************************************************) +(* Convert to ADMBase *) +(******************************************************************************) + +convertToADMBaseCalc = +{ + Name -> thorn <> "_convertToADMBase", + Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, + Where -> Everywhere, + Shorthands -> {e4phi}, + Equations -> + { + e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], + admg[la,lb] -> e4phi gt[la,lb], + admK[la,lb] -> e4phi At[la,lb] + (1/3) admg[la,lb] trK, + admalpha -> alpha, + admbeta[ua] -> beta[ua] + } +}; + +convertToADMBaseDtLapseShiftCalc = +{ + Name -> thorn <> "_convertToADMBaseDtLapseShift", + Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, + ConditionalOnKeyword -> {"dt_lapse_shift_method", "correct"}, + Where -> Interior, + Shorthands -> {dir[ua], detgt, gtu[ua,ub], eta, theta}, + Equations -> + { + dir[ua] -> Sign[beta[ua]], + + detgt -> 1 (* detgtExpr *), + (* This leads to simpler code... *) + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + + eta -> etaExpr, + theta -> thetaExpr, + + (* see RHS *) +(* + admdtalpha -> - harmonicF alpha^harmonicN + ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK) + + LapseAdvectionCoeff beta[ua] PDu[alpha,la], +*) + admdtalpha -> - harmonicF alpha^harmonicN + (+ LapseACoeff A + + ((1 - LapseACoeff) + (trK - IfCCZ4[2 Theta, 0]))) + + LapseAdvectionCoeff Upwind[beta[ua], alpha, la], + admdtbeta[ua] -> IfThen[harmonicShift, + - 1/2 gtu[ua,uj] phi alpha + (- 2 alpha PD[phi,lj] + + 2 phi PD[alpha,lj] + + gtu[uk,ul] phi alpha + (PD[gt[lk,ll],lj] - 2 PD[gt[lj,lk],ll])), + (* else *) + + theta ShiftGammaCoeff + (+ ShiftBCoeff B[ua] + + (1 - ShiftBCoeff) + (Xt[ua] - eta BetaDriver beta[ua]))] + + ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb] + } +}; + +convertToADMBaseDtLapseShiftBoundaryCalc = +{ + Name -> thorn <> "_convertToADMBaseDtLapseShiftBoundary", + Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, + ConditionalOnKeyword -> {"dt_lapse_shift_method", "correct"}, + Where -> BoundaryWithGhosts, + Shorthands -> {detgt, gtu[ua,ub], eta, theta}, + Equations -> + { + detgt -> 1 (* detgtExpr *), + (* This leads to simpler code... *) + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + + eta -> etaExpr, + theta -> thetaExpr, + + (* see RHS, but omit derivatives near the boundary *) +(* + admdtalpha -> - harmonicF alpha^harmonicN + ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK), +*) + admdtalpha -> - harmonicF alpha^harmonicN + (+ LapseACoeff A + + ((1 - LapseACoeff) + (trK - IfCCZ4[2 Theta, 0]))), + admdtbeta[ua] -> IfThen[harmonicShift, + 0, + (* else *) + + theta ShiftGammaCoeff + (+ ShiftBCoeff B[ua] + + (1 - ShiftBCoeff) + (Xt[ua] - eta BetaDriver beta[ua]))] + } +}; + +convertToADMBaseFakeDtLapseShiftCalc = +{ + Name -> thorn <> "_convertToADMBaseFakeDtLapseShift", + Schedule -> {"IN " <> thorn <> "_convertToADMBaseGroup"}, + ConditionalOnKeyword -> {"dt_lapse_shift_method", "noLapseShiftAdvection"}, + Where -> Everywhere, + Shorthands -> {detgt, gtu[ua,ub], eta, theta}, + Equations -> + { + detgt -> 1 (* detgtExpr *), + (* This leads to simpler code... *) + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + + eta -> etaExpr, + theta -> thetaExpr, + + (* see RHS, but omit derivatives everywhere (which is wrong, but + faster, since it does not require synchronisation or boundary + conditions) *) +(* + admdtalpha -> - harmonicF alpha^harmonicN + ((1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK), +*) + admdtalpha -> - harmonicF alpha^harmonicN + (+ LapseACoeff A + + ((1 - LapseACoeff) + (trK - IfCCZ4[2 Theta, 0]))), + admdtbeta[ua] -> IfThen[harmonicShift, + 0, + (* else *) + + theta ShiftGammaCoeff + (+ ShiftBCoeff B[ua] + + (1 - ShiftBCoeff) + (Xt[ua] - eta BetaDriver beta[ua]))] + } +}; + +(******************************************************************************) +(* Evolution equations *) +(******************************************************************************) + +evolCalc = +{ + Name -> thorn <> "_RHS", + Schedule -> {"IN " <> thorn <> "_evolCalcGroup"}, + (* + Where -> Interior, + *) + (* Synchronise the RHS grid functions after this routine, so that + the refinement boundaries are set correctly before applying the + radiative boundary conditions. *) + Where -> InteriorNoSync, + ConditionalOnKeyword -> {"RHS_split", "combined"}, + Shorthands -> {dir[ua], + detgt, gtu[ua,ub], + Gt[ua,lb,lc], Gtl[la,lb,lc], Gtlu[la,lb,uc], Xtn[ua], + Rt[la,lb], Rphi[la,lb], R[la,lb], + Atm[ua,lb], Atu[ua,ub], + e4phi, em4phi, cdphi[la], cdphi2[la,lb], g[la,lb], detg, + gu[ua,ub], Ats[la,lb], trAts, eta, theta, + rho, S[la], trS, fac1, fac2, dottrK, dotXt[ua], + epsdiss[ua], IfCCZ4[Z[ua]], IfCCZ4[dotTheta]}, + Equations -> + { + dir[ua] -> Sign[beta[ua]], + + detgt -> 1 (* detgtExpr *), + + (* This leads to simpler code... *) + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + Gtl[la,lb,lc] -> 1/2 + (PD[gt[lb,la],lc] + PD[gt[lc,la],lb] - PD[gt[lb,lc],la]), + Gtlu[la,lb,uc] -> gtu[uc,ud] Gtl[la,lb,ld], + Gt[ua,lb,lc] -> gtu[ua,ud] Gtl[ld,lb,lc], + + (* The conformal connection functions calculated from the conformal metric, + used instead of Xt where no derivatives of Xt are taken *) + Xtn[ui] -> gtu[uj,uk] Gt[ui,lj,lk], + + e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], + em4phi -> 1 / e4phi, + g[la,lb] -> e4phi gt[la,lb], + detg -> detgExpr, + gu[ua,ub] -> em4phi gtu[ua,ub], + + (* The Z quantities *) + (* gr-qc:1106.2254 (2011), eqn. (23) *) + IfCCZ4[ + Z[ud] -> (1/2) gu[ua,ud] (- PD[gt[la,lb],lc] gtu[ub,uc] + gt[la,lc] Xt[uc]) + ], + + (* PRD 62, 044034 (2000), eqn. (18) *) + (* Adding Z term by changing Xtn to Xt *) + Rt[li,lj] -> - (1/2) gtu[ul,um] PD[gt[li,lj],ll,lm] + + (1/2) gt[lk,li] PD[Xt[uk],lj] + + (1/2) gt[lk,lj] PD[Xt[uk],li] + + (1/2) Xtn[uk] Gtl[li,lj,lk] + + (1/2) Xtn[uk] Gtl[lj,li,lk] + + (+ Gt[uk,li,ll] Gtlu[lj,lk,ul] + + Gt[uk,lj,ll] Gtlu[li,lk,ul] + + Gt[uk,li,ll] Gtlu[lk,lj,ul]), + + fac1 -> IfThen[conformalMethod==CMW, -1/(2 phi), 1], + cdphi[la] -> fac1 CDt[phi,la], + fac2 -> IfThen[conformalMethod==CMW, 1/(2 phi^2), 0], + cdphi2[la,lb] -> fac1 CDt[phi,la,lb] + fac2 CDt[phi,la] CDt[phi,lb], + + (* PRD 62, 044034 (2000), eqn. (15) *) + Rphi[li,lj] -> - 2 cdphi2[lj,li] + - 2 gt[li,lj] gtu[ul,un] cdphi2[ll,ln] + + 4 cdphi[li] cdphi[lj] + - 4 gt[li,lj] gtu[ul,un] cdphi[ln] cdphi[ll], + + Atm[ua,lb] -> gtu[ua,uc] At[lc,lb], + Atu[ua,ub] -> Atm[ua,lc] gtu[ub,uc], + + R[la,lb] -> Rt[la,lb] + Rphi[la,lb], + IfCCZ4[ + R[la,lb] -> R[la,lb] + (2/phi) (+ g[la,lc] Z[uc] PD[phi,lb] + + g[lb,lc] Z[uc] PD[phi,la] - g[la,lb] Z[uc] PD[phi,lc]) + + e4phi Z[uc] PD[gt[la,lb],lc] + ], + + (* Matter terms *) + + (* rho = n^a n^b T_ab *) + rho -> addMatter + (1/alpha^2 (T00 - 2 beta[ui] T0[li] + beta[ui] beta[uj] T[li,lj])), + + (* S_i = -p^a_i n^b T_ab, where p^a_i = delta^a_i + n^a n_i *) + S[li] -> addMatter (-1/alpha (T0[li] - beta[uj] T[li,lj])), + + (* trS = gamma^ij T_ij *) + trS -> addMatter (em4phi gtu[ui,uj] T[li,lj]), + + (* RHS terms *) + + (* PRD 62, 044034 (2000), eqn. (10) *) + (* PRD 67 084023 (2003), eqn. (16) and (23) *) + dot[phi] -> IfThen[conformalMethod==CMW, 1/3 phi, -1/6] + (alpha trK - PD[beta[ua],la]), + + (* PRD 62, 044034 (2000), eqn. (9) *) + (* gr-qc:1106.2254 (2011), eqn. (14) *) + (* removing trA from Aij ensures that detg = 1 *) + dot[gt[la,lb]] -> - 2 alpha (At[la,lb] - IfCCZ4[(1/3) At[lc,ld] gtu[uc,ud] gt[la,lb], 0]) + + gt[la,lc] PD[beta[uc],lb] + gt[lb,lc] PD[beta[uc],la] + - (2/3) gt[la,lb] PD[beta[uc],lc], + (* PRD 62, 044034 (2000), eqn. (20) *) + (* PRD 67 084023 (2003), eqn (26) *) + (* gr-qc:1106.2254 (2011), eqn. (19) *) + (* Adding Z terms by changing Xtn to Xt, + also adding extra Z and Theta terms *) + dotXt[ui] -> - 2 Atu[ui,uj] PD[alpha,lj] + + 2 alpha (+ Gt[ui,lj,lk] Atu[uk,uj] + - (2/3) gtu[ui,uj] PD[trK,lj] + + 6 Atu[ui,uj] cdphi[lj]) + + gtu[uj,ul] PD[beta[ui],lj,ll] + + (1/3) gtu[ui,uj] PD[beta[ul],lj,ll] + - Xtn[uj] PD[beta[ui],lj] + + (2/3) Xtn[ui] PD[beta[uj],lj] + + IfCCZ4[ + + GammaShift 2 e4phi (- Z[uj] PD[beta[ui],lj] + + (2/3) Z[ui] PD[beta[uj],lj]) + - (4/3) alpha e4phi Z[ui] trK + + 2 gtu[ui,uj] (+ alpha PD[Theta,lj] + - Theta PD[alpha,lj]) + - 2 alpha e4phi dampk1 Z[ui], + 0] + (* Equation (4.28) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) + + addMatter (- 16 Pi alpha gtu[ui,uj] S[lj]), + dot[Xt[ui]] -> dotXt[ui], + + (* gr-qc:1106.2254 (2011), eqn. (18) *) + IfCCZ4[ + dotTheta -> + - PD[alpha,la] Z[ua] - dampk1 (2 + dampk2) alpha Theta + + (1/2) alpha (gu[ua,ub] R[la,lb] - Atm[ua,lb] Atm[ub,la] + (2/3) trK^2 - 2 trK Theta) + + addMatter (- 8 Pi alpha rho) + ], + + IfCCZ4[ + dot[Theta] -> dotTheta + ], + + (* PRD 62, 044034 (2000), eqn. (11) *) + (* gr-qc:1106.2254 (2011), eqn. (17) *) + (* Adding the RHS of Theta to K, because K_Z4 = K_BSSN + 2 Theta *) + (* Also adding the Z term, as it has to cancel with the one in Theta *) + dottrK -> - em4phi ( gtu[ua,ub] ( PD[alpha,la,lb] + + 2 cdphi[la] PD[alpha,lb] ) + - Xtn[ua] PD[alpha,la] ) + + alpha (Atm[ua,lb] Atm[ub,la] + (1/3) trK^2) + + IfCCZ4[ + + 2 dotTheta + 2 PD[alpha,la] Z[ua] + + dampk1 (1 - dampk2) alpha Theta, + 0] + (* Equation (4.21) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) + + addMatter (4 Pi alpha (rho + trS)), + dot[trK] -> dottrK, + + (* PRD 62, 044034 (2000), eqn. (12) *) + (* TODO: Should we use the Hamiltonian constraint to make Rij tracefree? *) + (* gr-qc:1106.2254 (2011), eqn. (15) *) + (* Adding Z terms in the Ricci and Theta terms *) + Ats[la,lb] -> - CDt[alpha,la,lb] + + + 2 (PD[alpha,la] cdphi[lb] + PD[alpha,lb] cdphi[la] ) + + alpha R[la,lb], + trAts -> gu[ua,ub] Ats[la,lb], + dot[At[la,lb]] -> + em4phi (+ Ats[la,lb] - (1/3) g[la,lb] trAts ) + + alpha (+ ((trK - IfCCZ4[2 Theta, 0]) + At[la,lb]) + - 2 At[la,lc] Atm[uc,lb]) + + At[la,lc] PD[beta[uc],lb] + At[lb,lc] PD[beta[uc],la] + - (2/3) At[la,lb] PD[beta[uc],lc] + (* Equation (4.23) in Baumgarte & Shapiro (Phys. Rept. 376 (2003) 41-131) *) + + addMatter (- em4phi alpha 8 Pi + (T[la,lb] - (1/3) g[la,lb] trS)), + + (* dot[alpha] -> - harmonicF alpha^harmonicN trK, *) + (* dot[alpha] -> - harmonicF alpha^harmonicN A + Lie[alpha, beta], *) +(* + dot[alpha] -> - harmonicF alpha^harmonicN ( + (1 - LapseAdvectionCoeff) A + LapseAdvectionCoeff trK) + + LapseAdvectionCoeff beta[ua] PDu[alpha,la], + dot[A] -> (1 - LapseAdvectionCoeff) (dottrK - AlphaDriver A), +*) + dot[alpha] -> - harmonicF alpha^harmonicN + (+ LapseACoeff A + + ((1 - LapseACoeff) + (+ trK - IfCCZ4[2 Theta, 0] + + AlphaDriver (alpha - 1)))), + + dot[A] -> + (LapseACoeff + (+ dottrK - IfCCZ4[2 dotTheta, 0] + - AlphaDriver A)), + + eta -> etaExpr, + theta -> thetaExpr, + + (* dot[beta[ua]] -> eta Xt[ua], *) + (* dot[beta[ua]] -> ShiftGammaCoeff alpha^ShiftAlphaPower B[ua], *) + dot[beta[ua]] -> IfThen[harmonicShift, + - 1/2 gtu[ua,uj] phi alpha + (- 2 alpha PD[phi,lj] + + 2 phi PD[alpha,lj] + + gtu[uk,ul] phi alpha + (PD[gt[lk,ll],lj] - 2 PD[gt[lj,lk],ll])), + (* else *) + + theta ShiftGammaCoeff + (+ ShiftBCoeff B[ua] + + (1 - ShiftBCoeff) + (Xt[ua] - eta BetaDriver beta[ua]))], + + dot[B[ua]] -> + ShiftBCoeff (dotXt[ua] - eta BetaDriver B[ua]) + (* Note that this dotXt[ua] is not yet \partial_t \tilde \Gamma^i, because the + advection term has not yet been added. It is actually + \partial_t \tilde \Gamma^i - \beta^j \partial_j \tilde \Gamma^i *) + } +}; + +advectCalc = +{ + Name -> thorn <> "_Advect", + Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> + "AFTER (" <> thorn <> "_RHS " <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, + (* + Where -> Interior, + *) + (* Synchronise the RHS grid functions after this routine, so that + the refinement boundaries are set correctly before applying the + radiative boundary conditions. *) + Where -> InteriorNoSync, + ConditionalOnKeyword -> {"advection_split", "combined"}, + Shorthands -> {dir[ua]}, + Equations -> + { + dir[ua] -> Sign[beta[ua]], + + dot[phi] -> dot[phi] + Upwind[beta[ua], phi, la], + + dot[gt[la,lb]] -> dot[gt[la,lb]] + Upwind[beta[uc], gt[la,lb], lc], + + dot[Xt[ui]] -> dot[Xt[ui]] + Upwind[beta[uj], Xt[ui], lj], + + IfCCZ4[ + dot[Theta] -> dot[Theta] + Upwind[beta[ua], Theta, la] + ], + + dot[trK] -> dot[trK] + Upwind[beta[ua], trK, la], + + dot[At[la,lb]] -> dot[At[la,lb]] + Upwind[beta[uc], At[la,lb], lc], + + dot[alpha] -> dot[alpha] + + LapseAdvectionCoeff Upwind[beta[ua], alpha, la], + + dot[A] -> dot[A] + + LapseACoeff ( + + LapseAdvectionCoeff Upwind[beta[ua], A, la] + + (1 - LapseAdvectionCoeff) Upwind[beta[ua], trK, la]), + + dot[beta[ua]] -> dot[beta[ua]] + + ShiftAdvectionCoeff Upwind[beta[ub], beta[ua], lb], + + dot[B[ua]] -> dot[B[ua]] + + ShiftBCoeff ( + + ShiftAdvectionCoeff Upwind[beta[ub], B[ua], lb] + + ((1 - ShiftAdvectionCoeff) + Upwind[beta[ub], Xt[ua], lb])) + (* Note that the advection term \beta^j \partial_j \tilde \Gamma^i is not + subtracted here when ShiftAdvectionCoefficient == 1 because it was + implicitly subtracted before (see comment in previous calculation of + dot[B[ua]]. *) + } +}; + +varsNames = { + {"phi", dot[phi]}, + {"gt", dot[gt[la,lb]]}, + {"Xt", dot[Xt[ui]]}, + {"trK", dot[trK]}, + {"At", dot[At[la,lb]]}, + {"alpha", dot[alpha]}, + {"A", dot[A]}, + {"beta", dot[beta[ua]]}, + {"B", dot[B[ua]]}, + IfCCZ4[{"Theta", dot[Theta]}] + }; + +advectCalcs = Map[ + PartialCalculation[advectCalc, "_"<>ToString[First[#]], + {ConditionalOnKeyword -> {"advection_split", + "per variable"}}, + {Last[#]}]&, + varsNames]; + +evolCalc1 = PartialCalculation[evolCalc, "1", + { + ConditionalOnKeyword -> {"RHS_split", "split At"} + }, + { + dot[phi], + dot[gt[la,lb]], + dot[Xt[ui]], + dot[trK], + dot[alpha], + dot[A], + dot[beta[ua]], + dot[B[ua]], + IfCCZ4[dot[Theta]] + }]; + +evolCalc2 = PartialCalculation[evolCalc, "2", + { + ConditionalOnKeyword -> {"RHS_split", "split At"} + }, + { + dot[At[la,lb]] + }]; + +dissCalc = +{ + Name -> thorn <> "_Dissipation", + Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> + "AFTER (" <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, + ConditionalOnKeyword -> {"apply_dissipation", "always"}, + Where -> InteriorNoSync, + Shorthands -> {epsdiss[ua]}, + Equations -> + { + epsdiss[ua] -> EpsDiss, + Sequence@@Table[ + dot[var] -> dot[var] + epsdiss[ux] PDdiss[var,lx], + {var, {phi, gt[la,lb], Xt[ui], IfCCZ4[Theta], trK, At[la,lb], + alpha, A, beta[ua], B[ua]}}] + } +}; + +dissCalcs = +Table[ +{ + Name -> thorn <> "_Dissipation_" <> ToString[var /. {Tensor[n_,__] -> n}], + Schedule -> {"IN " <> thorn <> "_evolCalcGroup " <> + "AFTER (" <> thorn <> "_RHS1 " <> thorn <> "_RHS2)"}, + ConditionalOnKeyword -> {"apply_dissipation", "always"}, + Where -> InteriorNoSync, + Shorthands -> {epsdiss[ua]}, + Equations -> + { + epsdiss[ua] -> EpsDiss, + dot[var] -> dot[var] + epsdiss[ux] PDdiss[var,lx] + } +}, + {var, {phi, gt[la,lb], Xt[ui], IfCCZ4[Theta], trK, At[la,lb], + alpha, A, beta[ua], B[ua]}} +]; + +RHSStaticBoundaryCalc = +{ + Name -> thorn <> "_RHSStaticBoundary", + Schedule -> {"IN MoL_CalcRHS"}, + ConditionalOnKeyword -> {"my_rhs_boundary_condition", "static"}, + Where -> Boundary, + Equations -> + { + dot[phi] -> 0, + dot[gt[la,lb]] -> 0, + dot[trK] -> 0, + dot[At[la,lb]] -> 0, + dot[Xt[ua]] -> 0, + dot[alpha] -> 0, + dot[A] -> 0, + dot[beta[ua]] -> 0, + dot[B[ua]] -> 0, + IfCCZ4[dot[Theta] -> 0] + } +}; + +(* Initialise the RHS variables in analysis in case they are going to + be output - the noninterior points cannot be filled, so we define + them to be zero *) +initRHSCalc = +{ + Name -> thorn <> "_InitRHS", + Schedule -> {"AT analysis BEFORE " <> thorn <> "_evolCalcGroup"}, + Where -> Everywhere, + Equations -> + { + dot[phi] -> 0, + dot[gt[la,lb]] -> 0, + dot[trK] -> 0, + dot[At[la,lb]] -> 0, + dot[Xt[ua]] -> 0, + dot[alpha] -> 0, + dot[A] -> 0, + dot[beta[ua]] -> 0, + dot[B[ua]] -> 0, + IfCCZ4[dot[Theta] -> 0] + } +}; + +RHSRadiativeBoundaryCalc = +{ + Name -> thorn <> "_RHSRadiativeBoundary", + Schedule -> {"IN MoL_CalcRHS"}, + ConditionalOnKeyword -> {"my_rhs_boundary_condition", "radiative"}, + Where -> Boundary, + Shorthands -> {dir[ua], + detgt, gtu[ua,ub], em4phi, gu[ua,ub], + nn[la], nu[ua], nlen, nlen2, su[ua], + vg}, + Equations -> + { + dir[ua] -> Sign[normal[ua]], + + detgt -> 1 (* detgtExpr *), + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + em4phi -> IfThen[conformalMethod==CMW, phi^2, Exp[-4 phi]], + gu[ua,ub] -> em4phi gtu[ua,ub], + + nn[la] -> Euc[la,lb] normal[ub], + nu[ua] -> gu[ua,ub] nn[lb], + nlen2 -> nu[ua] nn[la], + nlen -> Sqrt[nlen2], + su[ua] -> nu[ua] / nlen, + + vg -> Sqrt[harmonicF], + + dot[phi] -> - vg su[uc] PDo[phi ,lc], + dot[gt[la,lb]] -> - su[uc] PDo[gt[la,lb],lc], + dot[trK] -> - vg su[uc] PDo[trK ,lc], + dot[At[la,lb]] -> - su[uc] PDo[At[la,lb],lc], + dot[Xt[ua]] -> - su[uc] PDo[Xt[ua] ,lc], + dot[alpha] -> - vg su[uc] PDo[alpha ,lc], + dot[A] -> - vg su[uc] PDo[A ,lc], + dot[beta[ua]] -> - su[uc] PDo[beta[ua] ,lc], + dot[B[ua]] -> - su[uc] PDo[B[ua] ,lc], + IfCCZ4[ + dot[Theta] -> - vg su[uc] PDo[Theta ,lc] + ] + } +}; + +enforceCalc = +{ + Name -> thorn <> "_enforce", + Schedule -> {"IN MoL_PostStepModify"}, + Shorthands -> {detgt, gtu[ua,ub], trAt}, + Equations -> + { + (* The following comment is still interesting, but is not correct + any more since it is now scheduled in MoL_PostStepModify instead: + + Enforcing the constraints needs to be a projection, because it + is applied in MoL_PostStep and may thus be applied multiple + times, not only during time evolution. Therefore detgt has to + be calculated correctly, without assuming that det gt_ij = 1, + which is not always the case (since we don't enforce it). On + the other hand, this may not be so important... *) + detgt -> 1 (* detgtExpr *), + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + + trAt -> gtu[ua,ub] At[la,lb], + + At[la,lb] -> At[la,lb] - (1/3) gt[la,lb] trAt, + + alpha -> Max[alpha, MinimumLapse] + } +}; + +(******************************************************************************) +(* Boundary conditions *) +(******************************************************************************) + +boundaryCalc = +{ + Name -> thorn <> "_boundary", + Schedule -> {"IN MoL_PostStep"}, + ConditionalOnKeyword -> {"my_boundary_condition", "Minkowski"}, + Where -> BoundaryWithGhosts, + Equations -> + { + phi -> IfThen[conformalMethod==CMW, 1, 0], + gt[la,lb] -> KD[la,lb], + trK -> 0, + At[la,lb] -> 0, + Xt[ua] -> 0, + alpha -> 1, + A -> 0, + beta[ua] -> 0, + B[ua] -> 0, + IfCCZ4[Theta -> 0] + } +}; + +(******************************************************************************) +(* Constraint equations *) +(******************************************************************************) + +constraintsCalc = +{ + Name -> thorn <> "_constraints", + Schedule -> Automatic, + After -> "MoL_PostStep", + Where -> Interior, + Shorthands -> {detgt, ddetgt[la], gtu[ua,ub], Z[ua], + Gt[ua,lb,lc], Gtl[la,lb,lc], Gtlu[la,lb,uc], Xtn[ua], + e4phi, em4phi, + g[la,lb], detg, gu[ua,ub], ddetg[la], G[ua,lb,lc], + Rt[la,lb], Rphi[la,lb], R[la,lb], trR, Atm[ua,lb], + gK[la,lb,lc], cdphi[la], cdphi2[la,lb], + rho, S[la], fac1, fac2}, + Equations -> + { + detgt -> 1 (* detgtExpr *), + ddetgt[la] -> 0 (* ddetgtExpr[la] *), + + (* This leads to simpler code... *) + gtu[ua,ub] -> 1/detgt detgtExpr MatrixInverse [gt[ua,ub]], + Gtl[la,lb,lc] -> 1/2 + (PD[gt[lb,la],lc] + PD[gt[lc,la],lb] - PD[gt[lb,lc],la]), + Gtlu[la,lb,uc] -> gtu[uc,ud] Gtl[la,lb,ld], + Gt[ua,lb,lc] -> gtu[ua,ud] Gtl[ld,lb,lc], + + (* The conformal connection functions calculated from the conformal metric, + used instead of Xt where no derivatives of Xt are taken *) + Xtn[ui] -> gtu[uj,uk] Gt[ui,lj,lk], + + e4phi -> IfThen[conformalMethod==CMW, 1/phi^2, Exp[4 phi]], + em4phi -> 1 / e4phi, + g[la,lb] -> e4phi gt[la,lb], + detg -> e4phi^3, + gu[ua,ub] -> em4phi gtu[ua,ub], + + (* The Z quantities *) + IfCCZ4[ + Z[ud] -> (1/2) gu[ua,ud] (- PD[gt[la,lb],lc] gtu[ub,uc] + gt[la,lc] Xt[uc]) + ], + + (* PRD 62, 044034 (2000), eqn. (18) *) + Rt[li,lj] -> - (1/2) gtu[ul,um] PD[gt[li,lj],ll,lm] + + (1/2) gt[lk,li] PD[Xt[uk],lj] + + (1/2) gt[lk,lj] PD[Xt[uk],li] + + (1/2) Xtn[uk] Gtl[li,lj,lk] + + (1/2) Xtn[uk] Gtl[lj,li,lk] + + (+ Gt[uk,li,ll] Gtlu[lj,lk,ul] + + Gt[uk,lj,ll] Gtlu[li,lk,ul] + + Gt[uk,li,ll] Gtlu[lk,lj,ul]), + + (* From the long turducken paper. + This expression seems to give the same result as the one from 044034. *) + (* TODO: symmetrise correctly: (ij) = (1/2) [i+j] *) +(* + Rt[li,lj] -> - (1/2) gtu[uk,ul] PD[gt[li,lj],lk,ll] + + gt[lk,li] PD[Xt[uk],lj] + gt[lk,lj] PD[Xt[uk],li] + + gt[li,ln] Gt[un,lj,lk] gtu[um,ua] gtu[uk,ub] PD[gt[la,lb],lm] + + gt[lj,ln] Gt[un,li,lk] gtu[um,ua] gtu[uk,ub] PD[gt[la,lb],lm] + + gtu[ul,us] (+ 2 Gt[uk,ll,li] gt[lj,ln] Gt[un,lk,ls] + + 2 Gt[uk,ll,lj] gt[li,ln] Gt[un,lk,ls] + + Gt[uk,li,ls] gt[lk,ln] Gt[un,ll,lj]), +*) + + (* Below would be a straightforward calculation, + without taking any Gamma^i into account. + This expression gives a different answer! *) +(* + Rt[la,lb] -> + Gt[u1,l2,la] Gt[l1,lb,u2] - Gt[u1,la,lb] Gt[l1,l2,u2] + + 1/2 gtu[u1,u2] (- PD[gt[l1,l2],la,lb] + PD[gt[l1,la],l2,lb] + - PD[gt[la,lb],l1,l2] + PD[gt[l2,lb],l1,la]), +*) + + fac1 -> IfThen[conformalMethod==CMW, -1/(2 phi), 1], + cdphi[la] -> fac1 CDt[phi,la], + fac2 -> IfThen[conformalMethod==CMW, 1/(2 phi^2), 0], + cdphi2[la,lb] -> fac1 CDt[phi,la,lb] + fac2 CDt[phi,la] CDt[phi,lb], + + (* PRD 62, 044034 (2000), eqn. (15) *) + Rphi[li,lj] -> - 2 cdphi2[lj,li] + - 2 gt[li,lj] gtu[ul,un] cdphi2[ll,ln] + + 4 cdphi[li] cdphi[lj] + - 4 gt[li,lj] gtu[ul,un] cdphi[ln] cdphi[ll], + + (* ddetg[la] -> PD[e4phi detg,la], *) + ddetg[la] -> e4phi ddetgt[la] + 4 detgt e4phi PD[phi,la], + (* TODO: check this equation, maybe simplify it by omitting ddetg *) + G[ua,lb,lc] -> Gt[ua,lb,lc] + + 1/(2 detg) (+ KD[ua,lb] ddetg[lc] + KD[ua,lc] ddetg[lb] + - (1/3) g[lb,lc] gu[ua,ud] ddetg[ld]), + + R[la,lb] -> + Rt[la,lb] + Rphi[la,lb], + + IfCCZ4[ + R[la,lb] -> R[la, lb] + (2/phi) (+ g[la,lc] Z[uc] PD[phi,lb] + + g[lb,lc] Z[uc] PD[phi,la] - g[la,lb] Z[uc] PD[phi,lc]) + + e4phi Z[uc] PD[gt[la,lb],lc] + ], + + trR -> gu[ua,ub] R[la,lb], + + (* K[la,lb] -> e4phi At[la,lb] + (1/3) g[la,lb] trK, *) + (* Km[ua,lb] -> gu[ua,uc] K[lc,lb], *) + Atm[ua,lb] -> gtu[ua,uc] At[lc,lb], + + (* Matter terms *) + + (* rho = n^a n^b T_ab *) + rho -> 1/alpha^2 (T00 - 2 beta[ui] T0[li] + beta[ui] beta[uj] T[li,lj]), + + (* S_i = -p^a_i n^b T_ab, where p^a_i = delta^a_i + n^a n_i *) + S[li] -> -1/alpha (T0[li] - beta[uj] T[li,lj]), + + (* Constraints *) + + (* H -> trR - Km[ua,lb] Km[ub,la] + trK^2, *) + (* PRD 67, 084023 (2003), eqn. (19) *) + H -> trR - Atm[ua,lb] Atm[ub,la] + (2/3) trK^2 - addMatter 16 Pi rho, + + (* gK[la,lb,lc] -> CD[K[la,lb],lc], *) +(* gK[la,lb,lc] -> + 4 e4phi PD[phi,lc] At[la,lb] + e4phi CD[At[la,lb],lc] + + (1/3) g[la,lb] PD[trK,lc], + M[la] -> gu[ub,uc] (gK[lc,la,lb] - gK[lc,lb,la]), *) + + M[li] -> + gtu[uj,uk] (CDt[At[li,lj],lk] + 6 At[li,lj] cdphi[lk]) + - (2/3) PD[trK,li] + - addMatter 8 Pi S[li], + (* TODO: use PRD 67, 084023 (2003), eqn. (20) *) + + (* det gamma-tilde *) + cS -> Log[detgt], + + (* Gamma constraint *) + cXt[ua] -> gtu[ub,uc] Gt[ua,lb,lc] - Xt[ua], + + (* trace A-tilde *) + cA -> gtu[ua,ub] At[la,lb] + } +}; + +constraintsCalc1 = PartialCalculation[constraintsCalc, "1", + {}, + { + H + }]; + +constraintsCalc2 = PartialCalculation[constraintsCalc, "2", + {}, + { + M[li], + cS, + cXt[ua], + cA + }]; + +(******************************************************************************) +(* Implementations *) +(******************************************************************************) + +inheritedImplementations = + Join[{"ADMBase"}, + If [addMatter!=0, {"TmunuBase"}, {}]]; + +(******************************************************************************) +(* Parameters *) +(******************************************************************************) + +inheritedKeywordParameters = {}; + +extendedKeywordParameters = +{ + { + Name -> "ADMBase::evolution_method", + AllowedValues -> {thorn} + }, + { + Name -> "ADMBase::lapse_evolution_method", + AllowedValues -> {thorn} + }, + { + Name -> "ADMBase::shift_evolution_method", + AllowedValues -> {thorn} + }, + { + Name -> "ADMBase::dtlapse_evolution_method", + AllowedValues -> {thorn} + }, + { + Name -> "ADMBase::dtshift_evolution_method", + AllowedValues -> {thorn} + } +}; + +keywordParameters = +{ + { + Name -> "my_initial_data", + (* Visibility -> "restricted", *) + (* Description -> "ddd", *) + AllowedValues -> {"ADMBase", "Minkowski"}, + Default -> "ADMBase" + }, + { + Name -> "my_initial_boundary_condition", + Visibility -> "restricted", + (* Description -> "ddd", *) + AllowedValues -> {"none"}, + Default -> "none" + }, + { + Name -> "my_rhs_boundary_condition", + Visibility -> "restricted", + (* Description -> "ddd", *) + AllowedValues -> {"none", "static", "radiative"}, + Default -> "none" + }, + { + Name -> "my_boundary_condition", + (* Visibility -> "restricted", *) + (* Description -> "ddd", *) + AllowedValues -> {"none", "Minkowski"}, + Default -> "none" + }, + { + Name -> "calculate_ADMBase_variables_at", + Visibility -> "restricted", + (* Description -> "ddd", *) + AllowedValues -> {"MoL_PostStep", "CCTK_EVOL", "CCTK_ANALYSIS"}, + Default -> "MoL_PostStep" + }, + { + Name -> "UseSpatialBetaDriver_UNUSED", + Visibility -> "restricted", + (* Description -> "ddd", *) + AllowedValues -> {"no", "yes"}, + Default -> "no" + }, + { + Name -> "dt_lapse_shift_method", + Description -> "Treatment of ADMBase dtlapse and dtshift", + AllowedValues -> {"correct", + "noLapseShiftAdvection" (* omit lapse and shift advection terms (faster) *) + }, + Default -> "correct" + }, + { + Name -> "apply_dissipation", + Description -> "Whether to apply dissipation to the RHSs", + AllowedValues -> {"always", + "never" (* yes and no keyword values confuse Cactus, and Kranc + doesn't support boolean parameters *) + }, + Default -> "never" + }, + { + Name -> "RHS_split", + Description -> "How to split RHS calculation", + AllowedValues -> {"combined", + "split At"}, + Default -> "split At" + }, + { + Name -> "advection_split", + Description -> "How to split advection calculation", + AllowedValues -> {"combined", + "per variable"}, + Default -> "combined" + } +}; + +intParameters = +{ + { + Name -> harmonicN, + Description -> "d/dt alpha = - f alpha^n K (harmonic=2, 1+log=1)", + Default -> 2 + }, + { + Name -> ShiftAlphaPower, + Default -> 0 + }, + { + Name -> conformalMethod, + Description -> "Treatment of conformal factor", + AllowedValues -> {{Value -> "0", Description -> "phi method"}, + {Value -> "1", Description -> "W method"}}, + Default -> 0 + }, + { + Name -> fdOrder, + Default -> derivOrder, + AllowedValues -> {2,4,6,8} + }, + { + Name -> harmonicShift, + Description -> "Whether to use the harmonic shift", + AllowedValues -> {{Value -> "0", Description -> "Gamma driver shift"}, + {Value -> "1", Description -> "Harmonic shift"}}, + Default -> 0 + } +}; + +realParameters = +{ + IfCCZ4[{ + Name -> GammaShift, + Description -> "Covariant shift term in Gamma", + Default -> 0.5 + }], + IfCCZ4[{ + Name -> dampk1, + Description -> "CCZ4 damping term 1 for Theta and Z", + Default -> 0 + }], + IfCCZ4[{ + Name -> dampk2, + Description -> "CCZ4 damping term 2 for Theta and Z", + Default -> 0 + }], + { + Name -> LapseACoeff, + Description -> "Whether to evolve A in time", + Default -> 0 + }, + { + Name -> harmonicF, + Description -> "d/dt alpha = - f alpha^n K (harmonic=1, 1+log=2)", + Default -> 1 + }, + { + Name -> AlphaDriver, + Default -> 0 + }, + { + Name -> ShiftBCoeff, + Description -> "Whether to evolve B^i in time", + Default -> 1 + }, + { + Name -> ShiftGammaCoeff, + Default -> 0 + }, + { + Name -> BetaDriver, + Default -> 0 + }, + { + Name -> LapseAdvectionCoeff, + Description -> "Factor in front of the lapse advection terms in 1+log", + Default -> 1 + }, + { + Name -> ShiftAdvectionCoeff, + Description -> "Factor in front of the shift advection terms in gamma driver", + Default -> 1 + }, + { + Name -> MinimumLapse, + Description -> "Minimum value of the lapse function", + Default -> -1 + }, + { + Name -> SpatialBetaDriverRadius, + Description -> "Radius at which the BetaDriver starts to be reduced", + AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, + Default -> 10^12 + }, + { + Name -> SpatialShiftGammaCoeffRadius, + Description -> "Radius at which the ShiftGammaCoefficient starts to be reduced", + AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, + Default -> 10^12 + }, + { + Name -> EpsDiss, + Description -> "Dissipation strength", + AllowedValues -> {{Value -> "(0:*", Description -> "Positive"}}, + Default -> 0 + } +}; + +(******************************************************************************) +(* Construct the thorns *) +(******************************************************************************) + +calculations = +Join[ +{ + initialCalc, + convertFromADMBaseCalc, + initGammaCalc, + convertFromADMBaseGammaCalc, + evolCalc, + evolCalc1, evolCalc2, + dissCalc, + advectCalc, + (*advectCalcs,*) + initRHSCalc, + RHSStaticBoundaryCalc, + (* RHSRadiativeBoundaryCalc, *) + enforceCalc, + boundaryCalc, + convertToADMBaseCalc, + convertToADMBaseDtLapseShiftCalc, + convertToADMBaseDtLapseShiftBoundaryCalc, + convertToADMBaseFakeDtLapseShiftCalc, + (* constraintsCalc, *) + constraintsCalc1, constraintsCalc2 +}, + advectCalcs + (*dissCalcs*) +]; + +CreateKrancThornTT [groups, ".", thorn, + Calculations -> calculations, + DeclaredGroups -> declaredGroupNames, + PartialDerivatives -> derivatives, + EvolutionTimelevels -> evolutionTimelevels, + DefaultEvolutionTimelevels -> 3, + UseJacobian -> True, + UseLoopControl -> True, + UseVectors -> useVectors, + UseOpenCL -> useOpenCL, + InheritedImplementations -> inheritedImplementations, + InheritedKeywordParameters -> inheritedKeywordParameters, + ExtendedKeywordParameters -> extendedKeywordParameters, + KeywordParameters -> keywordParameters, + IntParameters -> intParameters, + RealParameters -> realParameters +]; + +]; + + + +(******************************************************************************) +(* Options *) +(******************************************************************************) + +(* These are the arguments to createComment: + - derivative order: 2, 4, 6, 8, ... + - useJacobian: False or True + - split upwind derivatives: False or True + - use vectorisation: False or True + - use OpenCL: False or True + - timelevels: 2 or 3 + ## (keep this at 3; this is better chosen with a run-time parameter) + - matter: 0 or 1 + ## (matter seems cheap; it should be always enabled) + - thorn base name +*) + +createCode[4, False, True, True , False, 3, 1, "BSSN"]; +createCode[4, False, True, False, False, 3, 1, "BSSN"]; +createCode[4, False, True, True , True , 3, 1, "BSSN"]; + +createCode[4, False, True, True , False, 3, 1, "CCZ4"]; + diff --git a/test/src_dir/matlab1.m b/test/src_dir/matlab1.m index dbb07b2..3e66995 100644 --- a/test/src_dir/matlab1.m +++ b/test/src_dir/matlab1.m @@ -52,3 +52,5 @@ % [T,true] = ode45(@logistic,[0,20],Nc,Options,r,K,theta); % subplot(1,2,2) % plot([1:tmax],P,'r.-',T,true,'g.-') + + ... This is a seriously old-school comment. \ No newline at end of file diff --git a/test/src_dir/mysql-stale-table-sniper b/test/src_dir/mysql-stale-table-sniper new file mode 100644 index 0000000..ba1c3b8 --- /dev/null +++ b/test/src_dir/mysql-stale-table-sniper @@ -0,0 +1,151 @@ +#!/usr/bin/perl + +# This is mysql-table-sniper, a program to help remove tables from a MySQL server. +# +# This program is copyright (c) 2007 Baron Schwartz, baron at xaprb dot com. +# Feedback and improvements are welcome. +# +# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar +# systems, you can issue `man perlgpl' or `man perlartistic' to read these +# licenses. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 59 Temple +# Place, Suite 330, Boston, MA 02111-1307 USA. + +use strict; +use warnings FATAL => 'all'; + +use DBI; +use English qw(-no_match_vars); +use Getopt::Long; +use List::Util qw(max); + +our $VERSION = '@VERSION@'; + +$OUTPUT_AUTOFLUSH = 1; + +# ############################################################################ +# Get configuration information. +# ############################################################################ + + print <selectcol_arrayref('SHOW DATABASES')}; +my @whole_batch; + +DATABASE: +foreach my $database ( @databases ) { + + # Ignore databases as instructed. Also ignore INFORMATION_SCHEMA and skip + # databases caused by lost+found directories created in the root of ext3 + # filesystems; they are not really databases. + next DATABASE if + ( $opts{d} && !exists($opts{d}->{$database}) ) + || $database =~ m/^(information_schema|lost\+found)$/mi + || exists $opts{g}->{$database}; + + my @tables = @{$dbh->selectcol_arrayref('SHOW TABLES FROM `' . $database . '`')}; + next DATABASE unless @tables; + + my %info_for; + + # Get a list of active connections + my $processes = $dbh->selectall_hashref("show processlist", 'Id'); + + foreach my $db ( @{ $dbh->selectcol_arrayref('show databases') } ) { + my @tables = @{ $dbh->selectcol_arrayref("show tables from $db") }; + foreach my $tbl ( @tables ) { + + # We only want tables whose name ends in digits NOT preceded by other + # digits (for example, barontest_2006_12_06 should not be dropped). + my ( $process ) = $tbl =~ m/\D_(\d+)$/; + + next unless $process; + + # If the process doesn't exist anymore, the table isn't in use. + if ( !exists($processes->{$process} ) ) { + print "Dropping table $db.$tbl\n" if $ENV{RKGDEBUG}; + $dbh->do("drop table if exists $db.$tbl"); + } + } + } + + TABLE: + foreach my $table ( @tables ) { + next TABLE if exists $opts{n}->{$table}; + + my $ddl = ($dbh->selectrow_array("SHOW CREATE TABLE `$database`.`$table`"))[1]; + next TABLE if $ddl =~ m/^CREATE ALGORITHM/; + + } + +} + +# ############################################################################ +# Subroutines +# ############################################################################ + +# ############################################################################ +# Documentation +# ############################################################################ + +=pod + +=head1 NAME + +mysql-stale-table-sniper - Find and possibly remove stale MySQL tables. + +=head1 DESCRIPTION + +=head1 OUTPUT + +=head1 SYSTEM REQUIREMENTS + +You need the following Perl modules: DBI and DBD::mysql. + +=head1 LICENSE + +This program is copyright (c) 2007 Baron Schwartz, baron at xaprb dot com. +Feedback and improvements are welcome. + +THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, version 2; OR the Perl Artistic License. On UNIX and similar +systems, you can issue `man perlgpl' or `man perlartistic' to read these +licenses. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA. + +=head1 AUTHOR + +Baron Schwartz, baron at xaprb dot com. + +=cut diff --git a/test/src_dir/nix.nix b/test/src_dir/nix.nix new file mode 100644 index 0000000..0c92adb --- /dev/null +++ b/test/src_dir/nix.nix @@ -0,0 +1,24 @@ +{pkgs,config}: + +# one line comment +{ +/* mulpiple line comment + foo = 21; +*/ + bar = " + #!/bin/sh + + ls -la + # comment + echo hello #comment + "; + + baz = '' + #!/bin/sh + + ls -la + # comment + echo hello #comment + ''; + nixHttp = [ http://nixos.org/ ]; +} diff --git a/test/src_dir/objj.j b/test/src_dir/objj.j new file mode 100644 index 0000000..88cb674 --- /dev/null +++ b/test/src_dir/objj.j @@ -0,0 +1,25 @@ + +@import +@import + +@import "Superclass.j" + +/* + I'm commenting this class +*/ +@implementation Class : Superclass +{ + var x @accessors; +} + ++ (void)classMethod +{ + return self; // this is a comment +} + +- (void)instanceMethod +{ + return self; +} + +@end diff --git a/test/src_dir/octave1.m b/test/src_dir/octave1.m new file mode 100644 index 0000000..4c795fb --- /dev/null +++ b/test/src_dir/octave1.m @@ -0,0 +1,301 @@ +## Copyright (C) 2006, Regents of the University of California -*- mode: octave; -*- +## +## This program is free software distributed under the "modified" or +## 3-clause BSD license appended to this file. + +function varargout = toledolu(LU) + ## (*- texinfo -*) + ## @deftypefn{Function File} {[@var{L}, @var{U}, @var{P}]} = toledolu(@var{A}) + ## @deftypefnx{Function File} {[@var{L}, @var{U}]} = toledolu(@var{A}) + ## @deftypefnx{Function File} {@var{LUP}} = toledolu(@var{A}) + ## + ## Note: This returns a vector of indices for @var{P} and not a permutation + ## matrix. + ## + ## Factors @var{P}*@var{A}=@var{L}*@var{U} by Sivan Toledo's recursive factorization algorithm + ## with partial pivoting. While not as fast as the built-in LU, this + ## is significantly faster than the standard, unblocked algorithm + ## while remaining relatively easy to modify. + ## + ## See the help for lu for details about the other calling forms. + ## + ## For the algorithm, see + ## (* @itemize *) + ## (* @item *) + ## Toledo, Sivan. "Locality of reference in LU decomposition with + ## partial pivoting," SIAM J. of Matrix Analysis and Applications, + ## v18, n4, 1997. DOI: 10.1137/S0895479896297744 + ## @end itemize + ## + ## @seealso{lu} + ## + ## @end deftypefn + + ## Author: Jason Riedy + ## Keywords: linear-algebra, LU, factorization + ## Version: 0.2 + + ## This version isn't *quite* the same as Toledo's algorithm. I use a + ## doubling approach rather than using recursion. So non-power-of-2 + ## columns likely will be slightly different, but that shouldn't + ## affect the 'optimality' by more than a small constant factor. + + ## Also, I don't handle ncol > nrow optimally. The code factors the + ## first nrow columns and then updates the remaining ncol-nrow columns + ## with L. + + ## Might be worth eating the memory cost and tracking L separately. + ## The eye(n)+tril(LU,-1) could be expensive. + + switch (nargout) + case 0 + return; + case {1,2,3} + otherwise + usage ("[L,U,P] = lu(A), [P\\L, U] = lu(A), or (P\\L-I+U) = lu(A)"); + endswitch + + [nrow, ncol] = size(LU); + nstep = min(nrow, ncol); + + Pswap = zeros(nstep, 1); + + for j=1:nstep, + [pval, pind] = max(abs(LU(j:nrow, j))); + pind = pind + j - 1; + Pswap(j) = pind; + + kahead = bitand(j, 1+bitcmp(j)); # last 1 bit in j + kstart = j+1-kahead; + kcols = min(kahead, nstep-j); + + inds = kstart : j; + Ucol = j+1 : j+kcols; + Lrow = j+1 : nrow; + + ## permute just this column + if (pind != j) + tmp = LU(pind, j); + LU(pind, j) = LU(j,j); + LU(j,j) = tmp; + endif + ## apply pending permutations to L + n_to_piv = 1; + ipivstart = j; + jpivstart = j - n_to_piv; + while (n_to_piv < kahead) + pivcols = jpivstart : jpivstart+n_to_piv-1; + for ipiv = ipivstart:j, + pind = Pswap(ipiv); + if (pind != ipiv) + tmp = LU(pind, pivcols); + LU(pind, pivcols) = LU(ipiv, pivcols); + LU(ipiv, pivcols) = tmp; + endif + endfor + ipivstart -= n_to_piv; + n_to_piv *= 2; + jpivstart -= n_to_piv; + endwhile + + if (LU(j,j) != 0.0 && !isnan(LU(j,j))), + LU(j+1:nrow,j) /= LU(j,j); + endif + + if 0 == kcols, break; endif + + ## permute U to match perm already applied to L + for k = inds, + tmp = LU(Pswap(k), Ucol); + LU(Pswap(k), Ucol) = LU(k, Ucol); + LU(k, Ucol) = tmp; + endfor + + LU(inds, Ucol) = (eye(kahead) + tril(LU(inds, inds),-1)) \ LU(inds, Ucol); + LU(Lrow, Ucol) -= LU(Lrow, inds) * LU(inds, Ucol); + endfor + + ## handle pivot permutations in L out from the last step + npived = bitand(nstep, 1+bitcmp(nstep)); + j = nstep-npived; + while (j > 0) + n_to_piv = bitand(j, 1+bitcmp(j)); + + pivcols = j-n_to_piv+1 : j; + for ipiv = j+1:nstep, + pind = Pswap(ipiv); + if (pind != ipiv) + tmp = LU(pind, pivcols); + LU(pind, pivcols) = LU(ipiv, pivcols); + LU(ipiv, pivcols) = tmp; + endif + endfor + + j -= n_to_piv; + endwhile + + if (nrow < ncol), + Ucol = nrow+1 : ncol; + inds = 1:nrow; + for k = inds, + tmp = LU(Pswap(k), Ucol); + LU(Pswap(k), Ucol) = LU(k, Ucol); + LU(k, Ucol) = tmp; + endfor + LU(inds, Ucol) = (eye(nrow) + tril(LU(inds, inds),-1)) \ LU(inds, Ucol); + endif + + if (nargout == 1) + varargout{1} = LU; + return; + endif + + if nrow == ncol, + L = eye(nrow) + tril(LU, -1); + varargout{2} = triu(LU); + elseif nrow < ncol, + L = eye(nrow) + tril(LU, -1)(:,1:nrow); + varargout{2} = triu(LU); + else # nrow > ncol + L = tril(LU, -1); + for k=1:ncol, + L(k,k) = 1; + endfor + varargout{2} = triu(LU)(1:ncol,:); + endif + + if (nargout == 2) + for j = 1:nstep, + pind = Pswap(j); + tmp = L(pind,:); + L(pind,:) = L(j,:); + L(j,:) = tmp; + endfor + else # nargout == 3 + P = 1:nrow; + for j = 1:nstep, + tmp = P(j); + P(j) = P(Pswap(j)); + P(Pswap(j)) = tmp; + endfor + varargout{3} = P; + endif + varargout{1} = L; + +endfunction + +%!test +%! M = 15; +%! N = 15; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 16; +%! N = 16; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 17; +%! N = 17; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 8; +%! N = 17; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 8; +%! N = 15; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 7; +%! N = 17; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 7; +%! N = 15; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 17; +%! N = 8; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 15; +%! N = 8; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 17; +%! N = 7; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 15; +%! N = 7; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 31; +%! N = 17; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +%!test +%! M = 11; +%! N = 29; +%! A = rand(M,N); +%! [L,U,P] = toledolu(A); +%! assert(norm(L*U-A(P,:),inf), 0, M**2*N*eps) + +## Copyright (c) 2006, Regents of the University of California +## 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 University of California, Berkeley 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 REGENTS 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 REGENTS AND 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. diff --git a/test/src_dir/optimer b/test/src_dir/optimer new file mode 100755 index 0000000..ee41b53 --- /dev/null +++ b/test/src_dir/optimer @@ -0,0 +1,47 @@ +#!/bin/sh +# optimer – Masserer ordlistefilene til eit kjaptsøkt format. +# +# Copyright © 2008, 2009 Karl Ove Hufthammer . +# +# This file is part of Ordbanken. +# +# Ordbanken is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Utfør kommandoen på fila oppgjeven som førsteargument. +fil=$1 +echo $fil + +# Forklaring på filtreringskommandoane. +# grep: Filtrer vekk kommentarar (linjer som startar med «*»). +# fgrep: Filtrer unormerte ord. +# sed: Gjer om mellomrom i siste del av linja (der kodane er) til tabulatorar. +# (Korfor den kompliserte sed-kommandoen? Fordi kodane i utgangspunktet er +# skilde med mellomrom i staden for med tabulatorar. Dette ville ikkje vore +# noko problem om alle oppføringar besto av eitt ord, då «column» som +# standard handterer mellomrom og tabulatorar likt, men ordbanken har +# oppføringar som «på kryss og tvers», og då ville alle orda få kvar si +# kolonne (bruk «på» som oppslagsord for å sjå oppføringa). +# sed: Fjern kodar (på forma ) som inneheld tal (interne/uforståelige kodar). +# sed: Fjern kodar («ord» utan <>) som startar med tal (interne/uforståelige kodar). +# sed: Fjern talkoden på starten av linja. +# tr: Slå saman etterfølgjande tabulatorar til éin. +# sort: Sorter fila (slik at oppslag med «look» går raskare). +grep -v '^\*' $fil \ +| fgrep -v "unormert" \ +| sed -r 'h;s/^([^ ]+ [^ ]+ [^ ]+ )(.*)/\2/;s/ / /g;G;s/(.*)\n([^ ]+ [^ ]+ [^ ]+ )(.*)/\2\1/' \ +| sed -r 's/<[^>]*[0-9][^>]*>+/ /g' \ +| sed -r 's/ [0-9]+[^ ]*/ /g' \ +| sed -r 's/^[0-9]+\s+//' \ +| tr -s '\t' \ +| LC_ALL=C sort > "${fil%.txt}.dat" diff --git a/test/src_dir/perl_pod_to_eof.pl b/test/src_dir/perl_pod_to_eof.pl new file mode 100644 index 0000000..88d626a --- /dev/null +++ b/test/src_dir/perl_pod_to_eof.pl @@ -0,0 +1 @@ +=head NAME diff --git a/test/src_dir/prolog.pl b/test/src_dir/prolog.pl new file mode 100644 index 0000000..5a82d23 --- /dev/null +++ b/test/src_dir/prolog.pl @@ -0,0 +1,9 @@ +/* test file for Prolog parsing */ + +% this is a Prolog source file + +% select(Element, List, Remaining) + +select(H, [H| T], T). +select(H, [X| R], [X| T]) :- + select(H, R, T). diff --git a/test/src_dir/puppet1.pp b/test/src_dir/puppet1.pp new file mode 100644 index 0000000..dea2fd8 --- /dev/null +++ b/test/src_dir/puppet1.pp @@ -0,0 +1,145 @@ +class bob::open_ldap { + + define foo::server ( + $argsfile = undef, + $bdb_cachesize = '', + $bdb_checkpoint = '', + $bdb_directory = undef, + $bdb_idlcachesize = '', + $bdb_rootdn, + $bdb_rootpw, + $bdb_shm_key = '', + $bdb_suffix, + $conf_path = undef, + $conf_dir = undef, + $enable = false, + $include = [], + $includepath = undef, + $modulepath = '', + $modules = [], + $package = undef, + $pidfile = undef, + $sysconf_path = undef + ) { + + $resource_name = "bob_openldap_server" + + if($name != "params") { + fail("${resource_name}: This function is a singleton. Make sure the resource name is 'params'.") + } + + case $operatingsystem { + Fedora: { + case $operatingsystemrelease { + /^(12|13)$/: { + if(!$argsfile) { $_argsfile = "/var/run/openldap/slapd.args" } + if(!$bdb_directory) { $_bdb_directory = "/var/lib/ldap" } + if(!$conf_path) { $_conf_path = "/etc/openldap/slapd.conf" } + if(!$conf_dir) { $_conf_dir = "/etc/openldap/slapd.d" } + if(!$package) { $_package = ["openldap-servers"] } + if(!$pidfile) { $_pidfile = "/var/run/openldap/slapd.pid" } + if(!$service) { $_service = "slapd" } + if(!$sysconf_path) { $_sysconf_path = "/etc/sysconfig/ldap" } + } + } + } + } + + # Presume the OS did not match and because these args are necessary, just + # bail with an error. + if(!($_argsfile and $_bdb_directory and $_pidfile and $_conf_path and + $_package and $_service and $_sysconf_path and $_conf_dir)) { + fail("${resource_name}: Unsupported operating system: ${operatingsystem} version ${operatingsystemrelease} and you have not setup the args for: argsfile, bdb_directory, conf_dir, conf_path, package, pidfile, sysconf_path and service.") + } + + # Fix paths - add forward slashes at the end of strings without them + $_includepath = regsubst($includepath, '([^/])$', '\1/') + $_dbconf_path = "${_bdb_directory}/DB_CONFIG" + + # ... + file { + $_conf_path: + content => template("bob_openldap/slapd.conf"), + require => Package[$_package], + owner => "ldap", + group => "root", + mode => "0440", + notify => Service[$_service]; + $_sysconf_path: + content => template("bob_openldap/ldap.sysconf"), + require => Package[$_package], + owner => "root", + group => "root", + mode => "0644"; + $_conf_dir: + force => true, + ensure => absent, + before => Service[$_service]; + $_dbconf_path: + content => "", + notify => Service[$_service]; + } + package { + $_package: + ensure => installed; + } + service { + $_service: + ensure => $enable ? { + true => "running", + false => "stopped" + }, + enable => $enable, + hasstatus => true, + require => [ Package[$_package], File[$_conf_path] ]; + } + } + + define client ( + $base, + $network_timeout = '', + $path = undef, + $timeout = '', + $binddn = '', + $tls_cacertdir = undef, + $uri + ) { + + $resource_name = "bob_openldap_client" + + if($name != "params") { + fail("${resource_name}: This function is a singleton. Make sure the resource name is 'params'.") + } + + case $operatingsystem { + Fedora: { + case $operatingsystemrelease { + /^(12|13)$/: { + if(!$tls_cacertdir) { $_tls_cacertdir = "/etc/openldap/cacerts" } + if(!$path) { $_path = "/etc/openldap/ldap.conf" } + } + } + } + } + + # Presume the OS did not match and because these args are necessary, just + # bail with an error. + if(!($_tls_cacertdir and $_path)) { + fail("${resource_name}: Unsupported operating system: ${operatingsystem} version ${operatingsystemrelease} and you have not setup the args for: tls_cacertdir, path.") + } + + # Fix some vars, ready for templating + $_base = $base + $_binddn = $binddn + $_network_timeout = $network_timeout + $_timeout = $timeout + $_uri = $uri + + file { + $_path: + content => template("bob_openldap/ldap.conf") + } + + } + +} diff --git a/test/src_dir/rebol.r b/test/src_dir/rebol.r new file mode 100644 index 0000000..8e0b6ff --- /dev/null +++ b/test/src_dir/rebol.r @@ -0,0 +1,59 @@ +;; ================================================= +;; Script: new-suffix.r +;; downloaded from: www.REBOL.org +;; on: 1-Jun-2011 +;; at: 21:19:08.38986 UTC +;; owner: carl [script library member who can update +;; this script] +;; ================================================= +REBOL [ + Title: "Change File Extensions (Suffix)" + File: %new-suffix.r + Author: "Carl Sassenrath" + Date: 25-Jan-2005 + Purpose: { + Change the file extension (suffix) for files with a specific extension. + For example, change all .txt files to .r files in the current directory. + Displays a list of changes before it makes them. + } + Warning: "Back up your files first, just in case!" + License: "BSD - Use at your own risk." + Library: [ + level: 'beginner + platform: 'all + type: [tool] + domain: [files] + tested-under: none + support: none + license: 'bsd + see-also: none + ] +] + +from-suffix: %.txt +to-suffix: %.r + +bulk-rename: func [confirmed] [ + foreach file load %./ [ + if all [ + not find file #"/" ; (ignore directories) + from-suffix = find/last file #"." + ][ + new-file: copy file + append clear find/last new-file #"." to-suffix + either confirmed [ + print ["Renaming" file "to" new-file] + rename file new-file + ][ + print ["Will rename" file "to" new-file] + ] + ] + ] +] + +bulk-rename false +if not confirm "Are you sure you want to rename all those files?" [ + quit +] +bulk-rename true +ask "Done. Press enter." diff --git a/test/src_dir/rust.rs b/test/src_dir/rust.rs new file mode 100644 index 0000000..03906b0 --- /dev/null +++ b/test/src_dir/rust.rs @@ -0,0 +1,16 @@ +/* + * This is the example given by www.rust-lang.org + */ +// Line comments work too +fn main() { + let nums = [1, 2]; + let noms = ["Tim", "Eston", "Aaron", "Ben"]; + + let mut odds = nums.iter().map(|&x| x * 2 - 1); + + for num in odds { + do spawn { + println!("{:s} says hello from a lightweight thread!", noms[num]); + } + } +} diff --git a/test/src_dir/sample.i3 b/test/src_dir/sample.i3 new file mode 100644 index 0000000..8a0b394 --- /dev/null +++ b/test/src_dir/sample.i3 @@ -0,0 +1,12 @@ +(* Modula-3 *) INTERFACE M3Sample; (* file extension ".i3" *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString = 'this is a string within "a string" ...\n'; + dqString = "this is a string within 'a string' ...\n"; + +END M3Sample. diff --git a/test/src_dir/sample.m3 b/test/src_dir/sample.m3 new file mode 100644 index 0000000..7640dea --- /dev/null +++ b/test/src_dir/sample.m3 @@ -0,0 +1,12 @@ +(* Modula-3 *) MODULE M3Sample; (* file extension ".m3" *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString = 'this is a string within "a string" ...\n'; + dqString = "this is a string within 'a string' ...\n"; + +END M3Sample. diff --git a/test/src_dir/sample.mod b/test/src_dir/sample.mod new file mode 100644 index 0000000..4f8debe --- /dev/null +++ b/test/src_dir/sample.mod @@ -0,0 +1,12 @@ +MODULE Sample; (* in Modula-2 *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString = 'this is a string within "a string" ...'; + dqString = "this is a string within 'a string' ..."; + +END Sample. diff --git a/test/src_dir/sample.ob2 b/test/src_dir/sample.ob2 new file mode 100644 index 0000000..6355698 --- /dev/null +++ b/test/src_dir/sample.ob2 @@ -0,0 +1,12 @@ +(* Oberon-2 *) MODULE OberonSample; (* file extension ".ob2" *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString* = 'this is a string within "a string" ...'; + dqString* = "this is a string within 'a string' ..."; + +END OberonSample. diff --git a/test/src_dir/sample.obn b/test/src_dir/sample.obn new file mode 100644 index 0000000..9ad1e2b --- /dev/null +++ b/test/src_dir/sample.obn @@ -0,0 +1,12 @@ +(* Oberon *) MODULE OberonSample; (* file extension ".obn" *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString* = 'this is a string within "a string" ...'; + dqString* = "this is a string within 'a string' ..."; + +END OberonSample. diff --git a/test/src_dir/sampleDef.def b/test/src_dir/sampleDef.def new file mode 100644 index 0000000..cd7c9ed --- /dev/null +++ b/test/src_dir/sampleDef.def @@ -0,0 +1,12 @@ +DEFINITION MODULE Sample; (* in Modula-2 *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString = 'this is a string within "a string" ...'; + dqString = "this is a string within 'a string' ..."; + +END Sample. diff --git a/test/src_dir/sampleImp.mod b/test/src_dir/sampleImp.mod new file mode 100644 index 0000000..cd5189e --- /dev/null +++ b/test/src_dir/sampleImp.mod @@ -0,0 +1,12 @@ +IMPLEMENTATION MODULE Sample; (* in Modula-2 *) + +(* This is a comment *) + +(* This is a comment ... + ... spanning more than one line *) + +CONST + sqString = 'this is a string within "a string" ...'; + dqString = "this is a string within 'a string' ..."; + +END Sample. diff --git a/test/src_dir/scilab.sci b/test/src_dir/scilab.sci new file mode 100644 index 0000000..a01e1a6 --- /dev/null +++ b/test/src_dir/scilab.sci @@ -0,0 +1,35 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Serge STEER +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + +function I=sub2ind(dims,varargin) +//sub2ind is used to determine the equivalent single index +//corresponding to a given set of subscript values. + +//I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the +//row, column, ... subscripts in the arrays i1,i2,.. for an matrix of +//size dims. + +//I = sub2ind(dims,Mi) returns the linear index +//equivalent to the n subscripts in the columns of the matrix Mi for a matrix +//of size dims. + + d=[1;cumprod(matrix(dims(1:$-1),-1,1))] + for i=1:size(varargin) + if varargin(i)==[] then I=[],return,end + end + + if size(varargin)==1 then //subindices are the columns of the argument + I=(varargin(1)-1)*d+1 + else //subindices are given as separated arguments + I=1 + for i=1:size(varargin) + I=I+(varargin(i)-1)*d(i) + end + end +endfunction diff --git a/test/src_dir/sh2.sh b/test/src_dir/sh2.sh new file mode 100644 index 0000000..2e03cdb --- /dev/null +++ b/test/src_dir/sh2.sh @@ -0,0 +1,5 @@ +var="\ +Some string" + +# Now a comment +var="some new string" diff --git a/test/src_dir/vb.aspx b/test/src_dir/vb.aspx new file mode 100644 index 0000000..8b7669e --- /dev/null +++ b/test/src_dir/vb.aspx @@ -0,0 +1,26 @@ +<%@ Page Language="VB" %> + + + + Basic ASP.NET Web Page + + +
+

Welcome to ASP.NET

+

Type your name and click the button.

+

+ + +

+

+ +

+
+ + diff --git a/test/src_licenses/affero_1.rb b/test/src_licenses/affero_1.rb new file mode 100644 index 0000000..bda4932 --- /dev/null +++ b/test/src_licenses/affero_1.rb @@ -0,0 +1,15 @@ +# | This program is free software; you can redistribute it and/or modify it under the | +# | terms of the GNU Affero General Public License version 3 as published by the Free | +# | Software Foundation with the addition of the following permission added to Section | +# | 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK IN WHICH THE | +# | COPYRIGHT IS OWNED BY RUBYCAMPUS LLC, RUBYCAMPUS LLC DISCLAIMS THE WARRANTY OF NON | +# | INFRINGEMENT OF THIRD PARTY RIGHTS. | +# | | +# | This program is distributed in the hope that it will be useful, but WITHOUT ANY | +# | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | +# | PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. | +# | | +# | You should have received a copy of the GNU Affero General Public License along | +# | with this program; if not, see http://www.gnu.org/licenses or write to the Free | +# | Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | +# | USA. | diff --git a/test/src_licenses/avr-drv.c b/test/src_licenses/avr-drv.c new file mode 100644 index 0000000..ae96bcd --- /dev/null +++ b/test/src_licenses/avr-drv.c @@ -0,0 +1,30 @@ +/* Copyright (c) 2008, Sample Code + All rights reserved. + + Redistribution and use in source and binary forms, + with or without modification, are permitted provided + that the following conditions are met: + + 1.Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + 2.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. + + 3.Neither the name of the AVR-DRV 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 + OWNER 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. */ diff --git a/test/src_licenses/boost_t1.c b/test/src_licenses/boost_t1.c new file mode 100644 index 0000000..f03ca30 --- /dev/null +++ b/test/src_licenses/boost_t1.c @@ -0,0 +1,25 @@ +/* + * Boost Software License - Version 1.0 - August 17th, 2003 + * + * Permission is hereby granted, free of charge, to any person or organization + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to use, reproduce, display, distribute, + * execute, and transmit the Software, and to prepare derivative works of the + * Software, and to permit third-parties to whom the Software is furnished to + * do so, all subject to the following: + * + * The copyright notices in the Software and this entire statement, including + * the above license grant, this restriction and the following disclaimer, + * must be included in all copies of the Software, in whole or in part, and + * all derivative works of the Software, unless such copies or derivative + * works are solely in the form of machine-executable object code generated by + * a source language processor. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ diff --git a/test/src_licenses/boost_t2.c b/test/src_licenses/boost_t2.c new file mode 100644 index 0000000..b4821e0 --- /dev/null +++ b/test/src_licenses/boost_t2.c @@ -0,0 +1 @@ +// Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/test/src_licenses/bsd_2clause_ish_t2.c b/test/src_licenses/bsd_ish_t3.c similarity index 100% rename from test/src_licenses/bsd_2clause_ish_t2.c rename to test/src_licenses/bsd_ish_t3.c diff --git a/test/src_licenses/cecill-b.c b/test/src_licenses/cecill-b.c new file mode 100644 index 0000000..b22dfe6 --- /dev/null +++ b/test/src_licenses/cecill-b.c @@ -0,0 +1 @@ +// terms of the CeCILL-B diff --git a/test/src_licenses/cecill-c.c b/test/src_licenses/cecill-c.c new file mode 100644 index 0000000..7388236 --- /dev/null +++ b/test/src_licenses/cecill-c.c @@ -0,0 +1 @@ +// terms of the CeCILL-C diff --git a/test/src_licenses/cecill.c b/test/src_licenses/cecill.c new file mode 100644 index 0000000..959651d --- /dev/null +++ b/test/src_licenses/cecill.c @@ -0,0 +1 @@ +// terms of the CeCILL diff --git a/test/src_licenses/gpl3_or_later_t3.cpp b/test/src_licenses/gpl3_or_later_t3.cpp new file mode 100644 index 0000000..8f3df8b --- /dev/null +++ b/test/src_licenses/gpl3_or_later_t3.cpp @@ -0,0 +1,3 @@ +/*************************************************************** + * License: GPL version 3 or later + **************************************************************/ diff --git a/test/src_licenses/gpl3_t2.cs b/test/src_licenses/gpl3_t2.cs new file mode 100644 index 0000000..ea5798f --- /dev/null +++ b/test/src_licenses/gpl3_t2.cs @@ -0,0 +1,4 @@ +/* + * Licensed under the terms of the GNU GPL v3, with Classpath Linking Exception + * Licensed under the terms of the New BSD License for exclusive use by the Ensemble OS Project + */ diff --git a/test/src_licenses/gpl_line_wrap_2.c b/test/src_licenses/gpl_line_wrap_2.c deleted file mode 100644 index 7a71eae..0000000 --- a/test/src_licenses/gpl_line_wrap_2.c +++ /dev/null @@ -1,5 +0,0 @@ -/************************************************************************** - * The line break and comment syntax should not disrupt the license match * - * GNU General * - * Public License * - **************************************************************************/ diff --git a/test/src_licenses/i9_license_t1.sh b/test/src_licenses/i9_license_t1.sh new file mode 100755 index 0000000..7780903 --- /dev/null +++ b/test/src_licenses/i9_license_t1.sh @@ -0,0 +1,43 @@ +# +# +# Copyright (C) 2008, 2009 i9 Project Contributors(1) +# All Rights Reserved. +# +# You may only modify and redistribute this under the terms of any of the +# following licenses(2): i9 License, MIT License +# +# +# (1) i9 Project Contributors are listed in the AUTHORS file and at +# http://i9os.googlecode.com/svn/trunk/Documentation/AUTHORS - please extend this file, +# not this notice. +# (2) Reproduced in the files in /Documentation/Licenses, and at: +# http://i9os.googlecode.com/svn/trunk/Documentation/Licenses +# +# As per the above licenses, removal of this notice is prohibited. +# +# ------------------------------------------------------------------------- +# + +cd Utilities +make -C ../BuildMk clean + +make -C ../Microkernel/user/serv/sigma0 clean + +make -C ../Microkernel/user/lib clean + +make -C ../Microkernel/user/serv/kickstart clean + +make -C ../Microkernel/user/apps/l4test clean + +cd ../Microkernel/user && make clean + +cd ../BuildMk && make clean +cd ../BuildL4UL && make clean + +cd ../Personalities/GenodeKit/build.pistachio_x86 && make clean + +cd .. + +rm *~ Documentation/*~ Documentation/*/*~ */*~ */*/~ + + diff --git a/test/src_licenses/i9_license_t2.sh b/test/src_licenses/i9_license_t2.sh new file mode 100755 index 0000000..31e720f --- /dev/null +++ b/test/src_licenses/i9_license_t2.sh @@ -0,0 +1,43 @@ +# +# +# Copyright (C) 2008, 2009 i9 Project Contributors(1) +# All Rights Reserved. +# +# You may only modify and redistribute this under the terms of any of the +# following licenses(2): i9 License +# +# +# (1) i9 Project Contributors are listed in the AUTHORS file and at +# http://i9os.googlecode.com/svn/trunk/Documentation/AUTHORS - please extend this file, +# not this notice. +# (2) Reproduced in the files in /Documentation/Licenses, and at: +# http://i9os.googlecode.com/svn/trunk/Documentation/Licenses +# +# As per the above licenses, removal of this notice is prohibited. +# +# ------------------------------------------------------------------------- +# + +cd Utilities +make -C ../BuildMk clean + +make -C ../Microkernel/user/serv/sigma0 clean + +make -C ../Microkernel/user/lib clean + +make -C ../Microkernel/user/serv/kickstart clean + +make -C ../Microkernel/user/apps/l4test clean + +cd ../Microkernel/user && make clean + +cd ../BuildMk && make clean +cd ../BuildL4UL && make clean + +cd ../Personalities/GenodeKit/build.pistachio_x86 && make clean + +cd .. + +rm *~ Documentation/*~ Documentation/*/*~ */*~ */*/~ + + diff --git a/test/src_licenses/lgpl3_t2.C b/test/src_licenses/lgpl3_t2.C new file mode 100644 index 0000000..a39c093 --- /dev/null +++ b/test/src_licenses/lgpl3_t2.C @@ -0,0 +1,15 @@ +// This file is part of MyProject. +// Copyright (C) 2005 University of California +// +// MyProject is free software: you can redistribute it and/or modify +// it under the terms of the gnu lesser general public license as published +// by the free software foundation, either version 3 of the license, or +// (at your option) any later version. +// +// MyProject is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License with MyProject. If not, see . diff --git a/test/src_licenses/wtfpl.c b/test/src_licenses/wtfpl.c new file mode 100644 index 0000000..443cfe6 --- /dev/null +++ b/test/src_licenses/wtfpl.c @@ -0,0 +1 @@ +// Do What The Fuck you Want to Public License 2 (WTFPL) diff --git a/test/symlink_test_dir/symlink_test_dir_target b/test/symlink_test_dir/symlink_test_dir_target new file mode 120000 index 0000000..733a6fa --- /dev/null +++ b/test/symlink_test_dir/symlink_test_dir_target @@ -0,0 +1 @@ +../symlink_test_dir_target/ \ No newline at end of file diff --git a/test/symlink_test_dir_target/from_symlink_foo.c b/test/symlink_test_dir_target/from_symlink_foo.c new file mode 100644 index 0000000..5c2fd48 --- /dev/null +++ b/test/symlink_test_dir_target/from_symlink_foo.c @@ -0,0 +1,4 @@ +// c file +int function_a(void) { + int x; +} diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 0a74c84..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'test/unit' -require 'fileutils' -require 'find' - -TEST_DIR = File.dirname(__FILE__) -require TEST_DIR + '/../lib/ohcount' - -# Ohcount::Test is a base class which includes several helper methods for parser testing. -# All unit tests in Ohcount should derive from this class. -# -# ==== Manual Testing -# -# To manually test a parser, rebuild ohcount and run it against your test file: -# -# rake -# bin/ohcount --annotate test/src_dir/my_file.ext -# -# The +annotate+ option will emit your test file to the console, and each line will be -# labeled as code, comment, or blank. -# -class Ohcount::Test < Test::Unit::TestCase - - # For reasons unknown, the base class defines a default_test method to throw a failure. - # We override it with a no-op to prevent this 'helpful' feature. - def default_test - end - - def src_dir - TEST_DIR + "/src_dir" - end - - def scratch_dir - TEST_DIR + "/scratch_dir" - end - - def expected_dir - TEST_DIR + "/expected_dir" - end - - # verify_parse runs a full test against a specified file. Detector is used to determine - # the correct parser, then the file is parsed and compared against expected results. - # - # The file to be parsed must be in directory test/src_dir. - # - # The expected results must be stored on disk in directory test/expected_dir. The format - # of the expected results on disk is a bit cumbersome. To create new test case, you must: - # - # 1. Create a new source code file in test/src_dir. - # For example, test/src_dir/my_file.ext - # - # 2. Next, create a new directory in test/expected_dir with - # the same name as your test source code file. For example, - # test/expected_dir/my_file.ext/ - # - # 3. Within this directory, create directories for each language used in the test source code - # file. For example, test/expected_dir/my_file.ext/my_language/ - # - # 4. In this language subdirectory, create three files called +code+, +comment+, and +blanks+. - # The +code+ file should contain all of the lines from my_file.ext which are code lines. - # The +comment+ file should contain all comment lines. - # The +blanks+ file is a bit different: it should contain a single line with an integer - # which is the count of blank lines in the original file. - # - # There are numerous examples in the test directories to help you out. - # - def verify_parse(src_filename, filenames = []) - # re-make the output directory - Dir.mkdir scratch_dir unless File.exists? scratch_dir - output_dir = scratch_dir + "/#{ File.basename(src_filename) }" - FileUtils.rm_r(output_dir) if FileTest.directory?(output_dir) - Dir.mkdir output_dir - - complete_src_filename = src_dir + "/#{ src_filename }" - sfc = Ohcount::SimpleFileContext.new(complete_src_filename, filenames) - polyglot = Ohcount::Detector.detect(sfc) - - # parse - buffer = File.new(complete_src_filename).read - Ohcount::Parser.parse_to_dir(:dir => output_dir, - :buffer => buffer, - :polyglot => polyglot) - - # now compare - answer_dir = expected_dir + "/#{ File.basename(src_filename) }" - compare_dir(answer_dir, output_dir) - - # just to be sure, lets compare the total number of lines from the source file and the processed breakdown - compare_line_count(complete_src_filename, output_dir) - end - - - def compare_dir(expected, actual) - # make sure entries are identical - expected_entries = expected.entries.collect { |e| e[expected.size..-1] } - actual_entries = actual.entries.collect { |a| a[actual.size..-1] } - assert_equal expected_entries, actual_entries - - Dir.foreach(expected) do |entry| - next if [".", "..", ".svn"].include?(entry) - case File.ftype(expected+ "/" + entry) - when 'file' - File.open(expected + "/" + entry) do |e| - File.open(actual + "/" + entry) do |a| - assert_equal e.read, a.read, "file #{actual + "/" + entry} differs from expected" - end - end - when 'directory' - compare_dir(expected + "/" + entry, actual + "/" + entry) - else - assert false, "weird ftype" - end - end - end - - - def compare_line_count(src_file, scratch_dir) - code_lines = comment_lines = blanks = 0 - - Find.find(scratch_dir) do |path| - if FileTest.file?(path) - `wc -l #{ path }` =~ /^\s*(\d*)\b/ - case File.basename(path) - when 'code' - code_lines += $1.to_i - when 'comment' - comment_lines += $1.to_i - when 'blanks' - blanks += File.new(path).read.to_i - end - end - end - - # src file lines - `wc -l #{ src_file }` =~ /^\s*(\d*)\b/ - src_file_lines = $1.to_i - - # compare - assert_equal src_file_lines, (code_lines + comment_lines + blanks), "wc -l of output (code, comment, blanks) doesn't match the 'wc -l' of original" - end - - def entities_array(src_string, polyglot, *entities) - arr = Array.new - Ohcount::parse_entities(src_string, polyglot) do |lang, entity, s, e| - arr << src_string[s...e] if entities.include?(entity) - end - arr - end -end - diff --git a/test/unit/actionscript_test.rb b/test/unit/actionscript_test.rb deleted file mode 100644 index 3759081..0000000 --- a/test/unit/actionscript_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ActionscriptTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("actionscript", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "actionscript") - end - - def test_comprehensive - verify_parse("as1.as") - end - - def test_comment_entities - assert_equal('//comment', entities_array(' //comment', 'actionscript', :comment).first) - assert_equal('/*comment*/', entities_array(' /*comment*/', 'actionscript', :comment).first) - end -end diff --git a/test/unit/ada_test.rb b/test/unit/ada_test.rb deleted file mode 100644 index 5279a8e..0000000 --- a/test/unit/ada_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::AdaTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("ada", "", "--comment", 0)] - assert_equal lb, Ohcount::parse(" --comment", "ada") - end - - def test_comprehensive - verify_parse("ada1.ada") - end - - def test_comprehensive_adb - verify_parse("ada1.adb") - end - - def test_comment_entities - assert_equal('--comment', entities_array(' --comment', 'ada', :comment).first) - end -end diff --git a/test/unit/all_tests.c b/test/unit/all_tests.c new file mode 100644 index 0000000..f6192e1 --- /dev/null +++ b/test/unit/all_tests.c @@ -0,0 +1,29 @@ +// all_tests.c written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include + +#include "detector_test.h" +#include "license_test.h" +#include "loc_test.h" +#include "parser_test.h" +#include "sourcefile_test.h" + +void all_tests() { + printf("Running sourcefile tests\n"); + all_sourcefile_tests(); + printf("Running detector tests\n"); + all_detector_tests(); + printf("Running license tests\n"); + all_license_tests(); + printf("Running parser tests\n"); + all_parser_tests(); + printf("Running loc tests\n"); + all_loc_tests(); +} + +int main() { + all_tests(); + printf("ALL TESTS PASSED.\n"); + return 0; +} diff --git a/test/unit/assembler_test.rb b/test/unit/assembler_test.rb deleted file mode 100644 index 9f13377..0000000 --- a/test/unit/assembler_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::AssemblerTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("assembler", "", "!comment\n;comment", 0)] - assert_equal lb, Ohcount::parse(" !comment\n ;comment", "assembler") - end - - def test_comprehensive - verify_parse("assembler1.asm") - end - - def test_comprehensive_2 - verify_parse("assembler2.S") - end - - def test_comment_entities - assert_equal(['//comment', '; comment', '!comment'], - entities_array(" //comment\n; comment\n\t!comment", 'assembler', :comment)) - end -end diff --git a/test/unit/autoconf_test.rb b/test/unit/autoconf_test.rb deleted file mode 100644 index 8706b65..0000000 --- a/test/unit/autoconf_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::AutoconfTest < Ohcount::Test - def test_comprehensive - verify_parse("configure.ac") - end - - def test_comment_entities - assert_equal('dnl comment', entities_array(" dnl comment", 'autoconf', :comment).first) - end -end - diff --git a/test/unit/automake_test.rb b/test/unit/automake_test.rb deleted file mode 100644 index 57707b2..0000000 --- a/test/unit/automake_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::AutomakeTest < Ohcount::Test - def test_comprehensive - verify_parse("Makefile.am") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'automake', :comment).first) - end -end - diff --git a/test/unit/awk_test.rb b/test/unit/awk_test.rb deleted file mode 100644 index 8e9effc..0000000 --- a/test/unit/awk_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::AwkTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("awk", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "awk") - end - - def test_double_slash - lb = [Ohcount::LanguageBreakdown.new("awk", "\"\\\\\"\n", "#comment", 0)] - # awk doesn't recognize backslash escaping of double quote...weird - assert_equal lb, Ohcount::parse("\"\\\\\"\n#comment", "awk") - end - - def test_comprehensive - verify_parse("awk1.awk") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'awk', :comment).first) - end -end diff --git a/test/unit/basic_test.rb b/test/unit/basic_test.rb deleted file mode 100644 index 66fb7b8..0000000 --- a/test/unit/basic_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::BasicTest < Ohcount::Test - def test_sb_comments - lb = [Ohcount::LanguageBreakdown.new("structured_basic", "", "REM comment", 0)] - assert_equal lb, Ohcount::parse("REM comment", "structured_basic") - end - - def test_cb_comments - lb = [Ohcount::LanguageBreakdown.new("classic_basic", "", "100 REM comment", 0)] - assert_equal lb, Ohcount::parse(" 100 REM comment", "classic_basic") - end - - def test_comprehensive - verify_parse("classic_basic.b") - verify_parse("visual_basic.bas", "frx1.frx") - verify_parse("structured_basic.b") - verify_parse("structured_basic.bas") - verify_parse("classic_basic.bas") - end - - def test_comment_entities - assert_equal('REM comment', entities_array(" REM comment", 'structured_basic', :comment).first) - assert_equal('\'comment', entities_array(" 'comment", 'classic_basic', :comment).first) - end -end diff --git a/test/unit/bat_test.rb b/test/unit/bat_test.rb deleted file mode 100644 index 1538967..0000000 --- a/test/unit/bat_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::BatTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("bat", "", "REM comment", 0)] - assert_equal lb, Ohcount::parse(" REM comment", "bat") - end - - def test_comprehensive - verify_parse("bat1.bat") - end - - def test_comment_entities - assert_equal('rem comment', entities_array(" rem comment", 'bat', :comment).first) - end -end diff --git a/test/unit/boo_test.rb b/test/unit/boo_test.rb deleted file mode 100644 index 4bfba5b..0000000 --- a/test/unit/boo_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::BooTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("boo", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "boo") - end - - def test_block_comment - lb = [Ohcount::LanguageBreakdown.new("boo", "", "/*comment*/", 0)] - assert_equal lb, Ohcount::parse(" /*comment*/", "boo") - end - - def test_nested_block_comment - lb = [Ohcount::LanguageBreakdown.new("boo", "", "/* comment\n/* nested */\nstill a comment */", 0)] - assert_equal lb, Ohcount::parse(" /* comment\n /* nested */\n still a comment */", "boo") - end - - def test_doc_comments - lb = [Ohcount::LanguageBreakdown.new("boo", "", "\"\"\"\ndoc comment\n\"\"\"", 0)] - assert_equal lb, Ohcount::parse("\"\"\"\ndoc comment\n\"\"\"", "boo") - end - - def test_strings - lb = [Ohcount::LanguageBreakdown.new("boo", "\"abc#not a 'comment\"", "", 0)] - assert_equal lb, Ohcount::parse("\"abc#not a 'comment\"", "boo") - end - - def test_comprehensive - verify_parse("boo1.boo") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'boo', :comment).first) - assert_equal('//comment', entities_array(" //comment", 'boo', :comment).first) - end -end diff --git a/test/unit/c_test.rb b/test/unit/c_test.rb deleted file mode 100644 index fb1e6fd..0000000 --- a/test/unit/c_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::CTest < Ohcount::Test - - def test_comments - lb = [Ohcount::LanguageBreakdown.new("c", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "c") - end - - def test_empty_comments - lb = [Ohcount::LanguageBreakdown.new("c", "","//\n", 0)] - assert_equal lb, Ohcount::parse(" //\n", "c") - end - - - def test_block_comment - lb = [Ohcount::LanguageBreakdown.new("c", "","/*c*/", 0)] - assert_equal lb, Ohcount::parse("/*c*/", "c") - end - - def test_comprehensive - verify_parse("c1.c") - verify_parse("c_str.c") - end - - def test_comprehensive_in - verify_parse("c2.h.in") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'c', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'c', :comment).first) - end - -end diff --git a/test/unit/clearsilver_template_test.rb b/test/unit/clearsilver_template_test.rb deleted file mode 100644 index 51b48a8..0000000 --- a/test/unit/clearsilver_template_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ClearsilverTemplateTest < Ohcount::Test - - def test_comment - html_lb = Ohcount::LanguageBreakdown.new("html", "", "", 0) - clearsilver_template_lb = Ohcount::LanguageBreakdown.new("clearsilver", "", "#comment\n", 0) - assert_equal [html_lb, clearsilver_template_lb], Ohcount::parse("", "clearsilver_template") - end - - def test_comprehensive - verify_parse("clearsilver_template1.cs") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'clearsilver_template', :comment).first) - assert_equal('#comment', entities_array("", 'clearsilver_template', :comment).first) - end - -end diff --git a/test/unit/clearsilver_test.rb b/test/unit/clearsilver_test.rb deleted file mode 100644 index e471bea..0000000 --- a/test/unit/clearsilver_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ClearsilverTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("clearsilver", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "clearsilver") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'clearsilver', :comment).first) - end - -end diff --git a/test/unit/csharp_test.rb b/test/unit/csharp_test.rb deleted file mode 100644 index 68683b7..0000000 --- a/test/unit/csharp_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::CSharpTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("csharp", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "csharp") - end - - def test_comprehensive - verify_parse("cs1.cs") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'csharp', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'csharp', :comment).first) - end - -end diff --git a/test/unit/css_test.rb b/test/unit/css_test.rb deleted file mode 100644 index 2860f66..0000000 --- a/test/unit/css_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::CssTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("css", "", "/*comment*/", 0)] - assert_equal lb, Ohcount::parse(" /*comment*/", "css") - end - - def test_comprehensive - verify_parse("css1.css") - end - - def test_comment_entities - assert_equal('/*comment*/', entities_array(" /*comment*/", 'css', :comment).first) - end -end diff --git a/test/unit/d_test.rb b/test/unit/d_test.rb deleted file mode 100644 index f12cd46..0000000 --- a/test/unit/d_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::DTest < Ohcount::Test - - def test_comments - lb = [Ohcount::LanguageBreakdown.new("dmd", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "dmd") - end - - def test_empty_comments - lb = [Ohcount::LanguageBreakdown.new("dmd", "","//\n", 0)] - assert_equal lb, Ohcount::parse(" //\n", "dmd") - end - - def test_strings - lb = [Ohcount::LanguageBreakdown.new("dmd", "'/*' not a comment '*/'", "", 0)] - assert_equal lb, Ohcount::parse("'/*' not a comment '*/'", "dmd") - end - - def test_block_comment - lb = [Ohcount::LanguageBreakdown.new("dmd", "","/*d*/", 0)] - assert_equal lb, Ohcount::parse("/*d*/", "dmd") - - lb = [Ohcount::LanguageBreakdown.new("dmd", "","/+d+/", 0)] - assert_equal lb, Ohcount::parse("/+d+/", "dmd") - end - - def test_nested_block_comment - lb = [Ohcount::LanguageBreakdown.new("dmd", "","/+ /*d*/ not_code(); +/", 0)] - assert_equal lb, Ohcount::parse("/+ /*d*/ not_code(); +/", "dmd") - end - - def test_comprehensive - verify_parse("d1.d") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'dmd', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'dmd', :comment).first) - assert_equal('/+comment+/', entities_array(" /+comment+/", 'dmd', :comment).first) - end - -end diff --git a/test/unit/dcl_test.rb b/test/unit/dcl_test.rb deleted file mode 100644 index 77d6efe..0000000 --- a/test/unit/dcl_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::DclTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("dcl", "", "$!comment", 0)] - assert_equal lb, Ohcount::parse("$!comment", "dcl") - end - - def test_code - lb= [Ohcount::LanguageBreakdown.new("dcl", "$code", "", 0)] - assert_equal lb, Ohcount::parse("$code", "dcl") - end - - def test_blank - lb=[Ohcount::LanguageBreakdown.new("dcl", "", "", 1)] - assert_equal lb, Ohcount::parse("\n", "dcl") - end - - def test_input_line - lb=[Ohcount::LanguageBreakdown.new("dcl", "input", "", 0)] - assert_equal lb, Ohcount::parse("input", "dcl") - end - - - def test_comprehensive - verify_parse("dcl.com") - end - - def test_comment_entities - assert_equal('!comment', entities_array(" !comment", 'dcl', :comment).first) - end -end diff --git a/test/unit/detector_test.h b/test/unit/detector_test.h new file mode 100755 index 0000000..597aed6 --- /dev/null +++ b/test/unit/detector_test.h @@ -0,0 +1,273 @@ +// detector_test.h written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include +#include +#include +#include + +#include "../../src/detector.h" +#include "../../src/languages.h" +#include "../../src/sourcefile.h" + +char **get_filenames(SourceFile *sourcefile) { + if (sourcefile->filenames == NULL) { + char dirpath[FILENAME_MAX]; + strncpy(dirpath, sourcefile->filepath, sourcefile->dirpath); + dirpath[sourcefile->dirpath] = '\0'; + struct dirent *file; + DIR *d = opendir((const char *)dirpath); + if (d) { + int length = 0; + while ((file = readdir(d))) length++; + closedir(d); + + char **filenames = calloc(length + 1, sizeof(char *)); + int i = 0; + d = opendir((const char *)dirpath); + while ((file = readdir(d))) { + int len = strlen(file->d_name); + char *filename = malloc(len + 1); + strncpy(filename, file->d_name, len); + filename[len] = '\0'; + filenames[i++] = filename; + } + closedir(d); + sourcefile->filenames = filenames; + } + } + return sourcefile->filenames; +} + +#define ASSERT_DETECT(x, y) { \ + SourceFile *sf = ohcount_sourcefile_new("../detect_files/" y); \ + get_filenames(sf); \ + const char *lang = ohcount_detect_language(sf); \ + assert(lang); \ + assert(strcmp(x, lang) == 0); \ + ohcount_sourcefile_free(sf); \ +} +#define ASSERT_NODETECT(x) { \ + SourceFile *sf = ohcount_sourcefile_new("../detect_files/" x); \ + get_filenames(sf); \ + assert(ohcount_detect_language(sf) == NULL); \ + ohcount_sourcefile_free(sf); \ +} + +void test_detector_smalltalk() { + ASSERT_DETECT(LANG_SMALLTALK, "example.st"); + ASSERT_NODETECT("english.st"); +} + +void test_detector_disambiguate_asx() { + ASSERT_DETECT(LANG_ASSEMBLER, "assembler6502.asx"); + ASSERT_NODETECT("AdvancedStreamRedirector.asx"); +} + +void test_detector_disambiguate_def() { + ASSERT_DETECT(LANG_MODULA2, "sampleDef.def"); + ASSERT_NODETECT("module-definition.def"); +} + +void test_detector_disambiguate_m() { + ASSERT_DETECT(LANG_OBJECTIVE_C, "t1.m"); + ASSERT_DETECT(LANG_OBJECTIVE_C, "t2.m"); + ASSERT_DETECT(LANG_OBJECTIVE_C, "TCPSocket.m"); + ASSERT_DETECT(LANG_OBJECTIVE_C, "foo_objective_c.m"); + ASSERT_DETECT(LANG_MATHEMATICA, "foo_mathematica.m"); + ASSERT_DETECT(LANG_MATLAB, "foo_matlab.m"); + ASSERT_DETECT(LANG_OCTAVE, "foo_octave.m"); +} + +void test_detector_disambiguate_in() { + ASSERT_NODETECT("empty.in"); + ASSERT_NODETECT("foo.in.in"); +} + +void test_detector_disambiguate_pl() { + ASSERT_DETECT(LANG_PERL, "foo_perl1.pl"); + ASSERT_DETECT(LANG_PERL, "foo_perl2.pl"); + ASSERT_DETECT(LANG_PROLOG, "foo_prolog1.pl"); + ASSERT_DETECT(LANG_PERL, "perl_with_smiley.pl"); + ASSERT_DETECT(LANG_PERL, "perl_shebang_prolog_body.pl"); +} + +void test_detector_disambiguate_pro() { + ASSERT_DETECT(LANG_IDL_PVWAVE, "foo.pro"); + ASSERT_DETECT(LANG_MAKE, "qmake.pro"); +} + +void test_detector_disambiguate_r() { + ASSERT_DETECT(LANG_R, "foo_r.R"); + ASSERT_DETECT(LANG_REBOL, "foo_rebol_lower.r"); + ASSERT_DETECT(LANG_REBOL, "foo_rebol_upper.r"); +} + +void test_detector_disambiguate_mod() { + ASSERT_DETECT(LANG_AMPL, "ampl.mod"); + ASSERT_DETECT(LANG_MODULA2, "modula2.mod"); +} + +void test_detector_disambiguate_dat() { + ASSERT_DETECT(LANG_AMPL, "ampl.dat"); + ASSERT_DETECT("\1", "binary.dat"); +} + +void test_detector_fortran_fixedfree() { + ASSERT_DETECT(LANG_FORTRANFIXED, "fortranfixed.f"); + ASSERT_DETECT(LANG_FORTRANFREE, "fortranfree.f"); +} + +void test_detector_detect_polyglot() { + ASSERT_DETECT(LANG_C, "foo.c"); + ASSERT_DETECT(LANG_C, "uses_no_cpp.h"); + ASSERT_DETECT(LANG_CPP, "uses_cpp_headers.h"); + ASSERT_DETECT(LANG_CPP, "uses_cpp_stdlib_headers.h"); + ASSERT_DETECT(LANG_CPP, "uses_cpp_keywords.h"); + ASSERT_DETECT(LANG_RUBY, "foo.rb"); + ASSERT_DETECT(LANG_MAKE, "foo.mk"); + ASSERT_DETECT(LANG_MATHEMATICA, "foo.mt"); + ASSERT_DETECT(LANG_MATHEMATICA, "foo.wl"); + ASSERT_DETECT(LANG_MATHEMATICA, "foo.wlt"); + ASSERT_DETECT(LANG_OBJECTIVE_C, "foo_objective_c.h"); + ASSERT_DETECT(LANG_PHP, "upper_case_php"); + ASSERT_DETECT(LANG_SMALLTALK, "example.st"); + ASSERT_DETECT(LANG_VALA, "foo.vala"); + ASSERT_DETECT(LANG_TEX_DTX, "foo.dtx"); + ASSERT_DETECT(LANG_TEX, "foo.tex"); + ASSERT_DETECT(LANG_XSLT, "example.xsl"); + ASSERT_DETECT(LANG_LOGTALK, "foo.lgt"); + ASSERT_DETECT(LANG_LISP, "core.lisp"); + ASSERT_DETECT(LANG_DMD, "foo.d"); + ASSERT_DETECT(LANG_VIM, "foo.vim"); + ASSERT_DETECT(LANG_EC, "foo.ec"); + ASSERT_DETECT(LANG_EC, "foo.eh"); + ASSERT_DETECT(LANG_EBUILD, "foo.ebuild"); + ASSERT_DETECT(LANG_EBUILD, "foo.eclass"); + ASSERT_DETECT(LANG_EXHERES, "foo.exheres-0"); + ASSERT_DETECT(LANG_EXHERES, "foo.exlib"); + ASSERT_DETECT(LANG_EIFFEL, "eiffel.e"); + ASSERT_DETECT(LANG_OCAML, "ocaml.ml"); + ASSERT_DETECT(LANG_AUGEAS, "augeas.aug"); + ASSERT_DETECT(LANG_STRATEGO, "stratego.str"); + ASSERT_DETECT(LANG_GLSL, "foo.glsl"); + ASSERT_DETECT(LANG_GLSL, "foo_glsl.vert"); + ASSERT_DETECT(LANG_GLSL, "foo_glsl.frag"); + ASSERT_DETECT(LANG_IDL_PVWAVE, "foo.pro"); + ASSERT_DETECT(LANG_ASSEMBLER, "foo.z80"); + ASSERT_DETECT(LANG_PHP, "php.inc"); + ASSERT_DETECT(LANG_FORTH, "forth.4th"); + ASSERT_DETECT(LANG_FORTH, "forth.fr"); + ASSERT_DETECT(LANG_FSHARP, "fs1.fs"); + ASSERT_DETECT(LANG_GRACE, "grace1.grace"); + ASSERT_DETECT(LANG_GRACE, "grace2.grc"); + ASSERT_DETECT(LANG_AUTOCONF, "m4.m4"); + ASSERT_DETECT(LANG_NSIS, "foo.nsi"); + ASSERT_DETECT(LANG_NSIS, "foo.nsh"); + ASSERT_DETECT(LANG_COFFEESCRIPT, "foo.coffee"); + ASSERT_DETECT(LANG_QML, "foo.qml"); + ASSERT_DETECT(LANG_COQ, "coq.v"); + ASSERT_DETECT(LANG_AMPL, "foo.run"); + ASSERT_NODETECT("empty.inc"); +} + +void test_detector_upper_case_extensions() { + ASSERT_DETECT(LANG_CPP, "foo_upper_case.C"); + ASSERT_DETECT(LANG_RUBY, "foo_upper_case.RB"); +} + +void test_detector_no_extensions() { + ASSERT_DETECT(LANG_PYTHON, "py_script"); + ASSERT_DETECT(LANG_RUBY, "ruby_script"); + ASSERT_DETECT(LANG_SHELL, "bourne_again_script"); + ASSERT_DETECT(LANG_SHELL, "bash_script"); + ASSERT_DETECT(LANG_PERL, "perl_w"); + ASSERT_DETECT(LANG_DMD, "d_script"); + ASSERT_DETECT(LANG_TCL, "tcl_script"); + ASSERT_DETECT(LANG_PYTHON, "python.data"); + ASSERT_DETECT(LANG_PYTHON, "python2.data"); + ASSERT_DETECT(LANG_CPP, "uses_cpp_modeline"); +} + +void test_detector_csharp_or_clearsilver() { + ASSERT_DETECT(LANG_CSHARP, "cs1.cs"); + ASSERT_DETECT(LANG_CLEARSILVER_TEMPLATE, "clearsilver_template1.cs"); +} + +void test_detector_basic() { + ASSERT_DETECT(LANG_VISUALBASIC, "visual_basic.bas"); + ASSERT_DETECT(LANG_CLASSIC_BASIC, "classic_basic.b"); + assert(system("mv ../detect_files/frx1.frx ../detect_files/frx1.frx2") == 0); + ASSERT_DETECT(LANG_STRUCTURED_BASIC, "visual_basic.bas"); + ASSERT_DETECT(LANG_STRUCTURED_BASIC, "structured_basic.b"); + assert(system("mv ../detect_files/frx1.frx2 ../detect_files/frx1.frx") == 0); +} + +void test_detector_xml_with_custom_extension() { + ASSERT_DETECT(LANG_XML, "xml.custom_ext"); +} + +void test_detector_brainfuck() { + ASSERT_DETECT(LANG_BRAINFUCK, "foo.bf"); + ASSERT_DETECT(LANG_BFPP, "foo.bfpp"); +} + +void test_detector_emacs_mode() { + ASSERT_DETECT(LANG_C, "emacs_mode_c"); +} + +void test_detector_emacs_with_extension() { + ASSERT_DETECT(LANG_RUBY, "java_emac.rb"); + ASSERT_DETECT(LANG_JAVASCRIPT, "javascript_emac.js"); +} + +void test_detector_puppet(){ + ASSERT_DETECT(LANG_PUPPET, "puppet_import.pp"); + ASSERT_DETECT(LANG_PUPPET, "puppet_test.pp"); +} + +void test_detector_genie(){ + ASSERT_DETECT(LANG_GENIE, "client-osx.gs"); +} + +void test_detector_rust(){ + ASSERT_DETECT(LANG_RUST, "rust.rs"); + // When RenderScript is implemented, this will, of course, need to be removed. + ASSERT_NODETECT("renderscript.rs"); +} + +void test_detector_ampl(){ + ASSERT_DETECT(LANG_AMPL, "foo.run"); +} + +void test_non_existent_file(){ + ASSERT_NODETECT("xxx_non_exists_xxxi.pp"); +} + +void all_detector_tests() { + test_detector_smalltalk(); + test_detector_disambiguate_asx(); + test_detector_disambiguate_def(); + test_detector_disambiguate_m(); + test_detector_disambiguate_in(); + test_detector_disambiguate_pl(); + test_detector_disambiguate_pro(); + test_detector_disambiguate_r(); + test_detector_disambiguate_mod(); + test_detector_disambiguate_dat(); + test_detector_fortran_fixedfree(); + test_detector_detect_polyglot(); + test_detector_upper_case_extensions(); + test_detector_no_extensions(); + test_detector_csharp_or_clearsilver(); + test_detector_basic(); + test_detector_xml_with_custom_extension(); + test_detector_brainfuck(); + test_detector_emacs_mode(); + test_detector_emacs_with_extension(); + test_detector_puppet(); + test_detector_genie(); + test_detector_rust(); + test_detector_ampl(); + test_non_existent_file(); +} diff --git a/test/unit/detector_test.rb b/test/unit/detector_test.rb deleted file mode 100644 index 6ca8a2e..0000000 --- a/test/unit/detector_test.rb +++ /dev/null @@ -1,110 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -include Ohcount - -# DetectorTest covers all Detector scenarios. -# -# The directory test/detect_files contains test files for the detector. -# These files are not used in parser testing; they are strictly for detection. -# -# ==== Manual Testing -# -# To manually test an addition to the detector, rebuild ohcount and run it against -# your test file: -# -# rake -# bin/ohcount --detect test/detect_files/my_file.ext -# -# If the detector is working, you should see the name of your expected language: -# -# my_language test/detect_files/my_file.ext -# -class Ohcount::DetectorTest < Ohcount::Test - - def do_detect(filename, filenames = []) - file_location = File.dirname(__FILE__) + "/../detect_files/" + filename - sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location) - Ohcount::Detector.detect(sfc) - end - - # Nonrecursively adds files from the file's directory to the context - def do_detect_with_siblings(filename) - file_location = File.dirname(__FILE__) + "/../detect_files/" + filename - filenames = Dir.entries(File.dirname(__FILE__) + File.dirname("/../detect_files/" + filename)) - [filename] - sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location) - Ohcount::Detector.detect(sfc) - end - - def test_matlab_or_objective_c - assert_equal 'objective_c', do_detect("t1.m") - assert_equal 'objective_c', do_detect("t2.m") - end - - def text_fortran_fixedfree - assert_equal 'fortranfixed', do_detect("fortranfixed.f") - assert_equal 'fortranfree', do_detect("fortranfree.f") - end - - def test_detect_polyglot - assert_equal "c", do_detect("foo.c") - assert_equal "c", do_detect("foo.c") - assert_equal "c", do_detect("uses_no_cpp.h") - assert_equal "cpp", do_detect("uses_cpp_headers.h") - assert_equal "cpp", do_detect("uses_cpp_stdlib_headers.h") - assert_equal "cpp", do_detect("uses_cpp_keywords.h") - assert_equal "ruby", do_detect("foo.rb") - assert_equal "make", do_detect("foo.mk") - assert_equal "matlab", do_detect("foo_matlab.m", ["foo_matlab.m", "bar.m", "README"]) - assert_equal "objective_c", do_detect("foo_objective_c.m", ["foo_objective_c.m", "bar.h", "README"]) - assert_equal "objective_c", do_detect("foo_objective_c.h", ["foo_objective_c.h, different_than_foo.m"]) - assert_equal "php", do_detect("upper_case_php") - assert_equal "smalltalk", do_detect("example.st") - assert_equal "vala", do_detect("foo.vala") - assert_equal "tex", do_detect("foo.tex") - assert_equal "xslt", do_detect("example.xsl") - assert_equal "lisp", do_detect("core.lisp") - assert_equal "dmd", do_detect("foo.d") - assert_equal "vim", do_detect("foo.vim") - assert_equal "ebuild", do_detect("foo.ebuild") - assert_equal "ebuild", do_detect("foo.eclass") - assert_equal "exheres", do_detect("foo.exheres-0") - assert_equal "exheres", do_detect("foo.exlib") - assert_equal "eiffel", do_detect("eiffel.e") - assert_equal "ocaml", do_detect("ocaml.ml") - assert_equal "stratego", do_detect("stratego.str") - end - - def test_upper_case_extensions - assert_equal "cpp", do_detect("foo_upper_case.C") - assert_equal "ruby", do_detect("foo_upper_case.RB") - end - - def test_no_extensions - assert_equal "python", do_detect("py_script", []) - assert_equal "ruby", do_detect("ruby_script", []) - assert_equal "shell", do_detect("bourne_again_script", []) - assert_equal "shell", do_detect("bash_script", []) - assert_equal "perl", do_detect("perl_w", []) - assert_equal "dmd", do_detect("d_script", []) - end - - def test_by_filename - assert_equal "autoconf", do_detect("configure.ac") - assert_equal "autoconf", do_detect("configure.in") - assert_equal "automake", do_detect("Makefile.am") - assert_equal "make", do_detect("Makefile") - end - - def test_csharp_or_clearsilver - assert_equal 'csharp', do_detect("cs1.cs") - assert_equal 'clearsilver_template', do_detect("clearsilver_template1.cs") - end - - def test_basic - assert_equal "structured_basic", do_detect("visual_basic.bas") - assert_equal "visualbasic", do_detect("visual_basic.bas", ["frx1.frx"]) - assert_equal "classic_basic", do_detect("classic_basic.b") - assert_equal "structured_basic", do_detect("structured_basic.b") - end - -end - diff --git a/test/unit/diff_test.rb b/test/unit/diff_test.rb deleted file mode 100644 index 91082b2..0000000 --- a/test/unit/diff_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::DiffTest < Ohcount::Test - - def test_one - src_dir = File.dirname(__FILE__) + '/../src_dir/' - sloc_infos = Ohcount.diff_files(src_dir + 'diff1_old.html', src_dir + 'diff1_new.html') - - css = Ohcount::SlocInfo.new('css') - css.code_added = 1 - css.comments_added = 1 - - html = Ohcount::SlocInfo.new('html') - html.code_added, html.code_removed = [1,1] - - js = Ohcount::SlocInfo.new('javascript') - js.code_removed = 1 - js.comments_removed = 1 - - assert_equal [css, html, js], sloc_infos - end - - def test_two - src_dir = File.dirname(__FILE__) + '/../src_dir/' - sloc_infos = Ohcount.diff_files(src_dir + 'diff2_old.c', src_dir + 'diff2_new.c') - - c = Ohcount::SlocInfo.new('c') - c.code_added, c.code_removed = [1,1] - c.comments_added, c.comments_removed = [1,1] - - assert_equal [c], sloc_infos - end - - def test_three - src_dir = File.dirname(__FILE__) + '/../src_dir/' - sloc_infos = Ohcount.diff_files(src_dir + 'diff3_old.xml', src_dir + 'diff3_new.xml') - - xml = Ohcount::SlocInfo.new('xml') - xml.code_added, xml.code_removed = [1,1] - - assert_equal [xml], sloc_infos - end -end diff --git a/test/unit/dylan_test.rb b/test/unit/dylan_test.rb deleted file mode 100644 index aa767e2..0000000 --- a/test/unit/dylan_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::DylanTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("dylan", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "dylan") - end - - def test_comprehensive - verify_parse("dylan1.dylan") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'dylan', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'dylan', :comment).first) - end -end diff --git a/test/unit/ebuild_test.rb b/test/unit/ebuild_test.rb deleted file mode 100644 index 3f4e2b3..0000000 --- a/test/unit/ebuild_test.rb +++ /dev/null @@ -1,11 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::EbuildTest < Ohcount::Test - def test_comprehensive - verify_parse("foo.ebuild") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'ebuild', :comment).first) - end -end diff --git a/test/unit/eiffel_test.rb b/test/unit/eiffel_test.rb deleted file mode 100644 index 0843082..0000000 --- a/test/unit/eiffel_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::EiffelTest < Ohcount::Test - def test_cb_comments - lb = [Ohcount::LanguageBreakdown.new("eiffel", "", "-- comment", 0)] - assert_equal lb, Ohcount::parse(" -- comment", "eiffel") - end - - def test_comprehensive - verify_parse("eiffel.e") - end - - def test_comment_entities - assert_equal('--comment', entities_array(" --comment", 'eiffel', :comment).first) - end - -end diff --git a/test/unit/emacs_lisp.rb b/test/unit/emacs_lisp.rb deleted file mode 100644 index 50b2fd2..0000000 --- a/test/unit/emacs_lisp.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::EmacsLispTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("emacslisp", "", ";;comment", 0)] - assert_equal lb, Ohcount::parse(" ;;comment", "emacslisp") - end - - def test_comprehensive - verify_parse("el1.el") - end - - def test_comment_entities - assert_equal(';comment', entities_array(" ;comment", 'emacslisp', :comment).first) - end - -end - - diff --git a/test/unit/erlang_test.rb b/test/unit/erlang_test.rb deleted file mode 100644 index f6be5a4..0000000 --- a/test/unit/erlang_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ErlangTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("erlang", "", "%%comment", 0)] - assert_equal lb, Ohcount::parse(" %%comment", "erlang") - end - - def test_comprehensive - verify_parse("erl1.erl") - end - - def test_comment_entities - assert_equal('%comment', entities_array(" %comment", 'erlang', :comment).first) - end - -end diff --git a/test/unit/exheres_test.rb b/test/unit/exheres_test.rb deleted file mode 100644 index 8d615ca..0000000 --- a/test/unit/exheres_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ExheresTest < Ohcount::Test - def test_comprehensive - verify_parse("foo.exheres-0") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'exheres', :comment).first) - end -end - diff --git a/test/unit/factor_test.rb b/test/unit/factor_test.rb deleted file mode 100644 index 50ebfa0..0000000 --- a/test/unit/factor_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::FactorTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("factor", "", "! comment", 0)] - assert_equal lb, Ohcount::parse(" ! comment", "factor") - end - - def test_strings - lb = [Ohcount::LanguageBreakdown.new("factor", "\"abc!not a 'comment\"", "", 0)] - assert_equal lb, Ohcount::parse("\"abc!not a 'comment\"", "factor") - end - - def test_comprehensive - verify_parse("factor1.factor") - end -end diff --git a/test/unit/fortran_test.rb b/test/unit/fortran_test.rb deleted file mode 100644 index d441f44..0000000 --- a/test/unit/fortran_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::FortranTest < Ohcount::Test - - def test_comprehensive - verify_parse("fortranfixed.f") - verify_parse("fortranfree.f") - end - - def test_comment_entities - assert_equal('!comment', entities_array(" !comment", 'fortranfree', :comment).first) - assert_equal('C comment', entities_array("C comment", 'fortranfixed', :comment).first) - end - -end diff --git a/test/unit/groovy_test.rb b/test/unit/groovy_test.rb deleted file mode 100644 index 04793a6..0000000 --- a/test/unit/groovy_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::GroovyTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("groovy", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "groovy") - end - - def test_comprehensive - verify_parse("groovy1.groovy") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'groovy', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'groovy', :comment).first) - end - -end diff --git a/test/unit/haml_test.rb b/test/unit/haml_test.rb deleted file mode 100644 index d65acb0..0000000 --- a/test/unit/haml_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::HamlTest < Ohcount::Test - def test_line_comment - lb = [Ohcount::LanguageBreakdown.new("haml", "", "/ comment", 0)] - assert_equal lb, Ohcount::parse("/ comment", "haml") - end - - def test_element - lb2 = [Ohcount::LanguageBreakdown.new("haml", "%code", "", 0)] - assert_equal lb2, Ohcount::parse(" %code", "haml") - end - - def test_element_entities - assert_equal("%element", entities_array(" %element", 'haml', :element).first) - assert_equal(".class", entities_array(" .class", 'haml', :element_class).first) - assert_equal("#id", entities_array(" #id", 'haml', :element_id).first) - end - - def test_comprehensive - verify_parse("haml.haml") - end -end diff --git a/test/unit/haskell_test.rb b/test/unit/haskell_test.rb deleted file mode 100644 index 51035bc..0000000 --- a/test/unit/haskell_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -# This has been shamelessly copied from java_test.rb because my Ruby is not so -# good and I don't really know what people expect from a Ohcount language test -# -- Reinier Lamers 2008-01-19 -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::HaskellTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("haskell", "", "--comment", 0)] - assert_equal lb, Ohcount::parse(" --comment", "haskell") - end - - def test_comprehensive - verify_parse("haskell1.hs") - end - - def test_comprehensive_with_carriage_returns - verify_parse("haskell2.hs") - end - - def test_comprehensive_with_nested_comments - verify_parse("haskell3.hs") - end - - def test_comment_entities - assert_equal('--comment', entities_array(" --comment", 'haskell', :comment).first) - assert_equal('{-comment-}', entities_array(" {-comment-}", 'haskell', :comment).first) - end -end diff --git a/test/unit/html_test.rb b/test/unit/html_test.rb deleted file mode 100644 index f6d007d..0000000 --- a/test/unit/html_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::HtmlTest < Ohcount::Test - def test_comprehensive - verify_parse("html1.html") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'html', :comment).first) - assert_equal('/*comment*/', entities_array("", 'html', :comment).first) - assert_equal('//comment', entities_array("", 'html', :comment).first) - assert_equal('/*comment*/', entities_array("", 'html', :comment).first) - end -end diff --git a/test/unit/java_test.rb b/test/unit/java_test.rb deleted file mode 100644 index 91ca3c8..0000000 --- a/test/unit/java_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::JavaTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("java", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "java") - end - - def test_comprehensive - verify_parse("java1.java") - end - - def test_comprehensive_with_carriage_returns - verify_parse("java2.java") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'java', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'java', :comment).first) - end -end diff --git a/test/unit/javascript_test.rb b/test/unit/javascript_test.rb deleted file mode 100644 index 52da443..0000000 --- a/test/unit/javascript_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::JavascriptTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("javascript", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "javascript") - end - - def test_comprehensive - verify_parse("js1.js") - end - - def test_comp2 - verify_parse("js2.js") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'javascript', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'javascript', :comment).first) - end - -end diff --git a/test/unit/jsp_test.rb b/test/unit/jsp_test.rb deleted file mode 100644 index d307c3f..0000000 --- a/test/unit/jsp_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::JspTest < Ohcount::Test - def test_comment - html_lb = Ohcount::LanguageBreakdown.new("html", "%>", "", 0) - java_lb = Ohcount::LanguageBreakdown.new("java", "", "<% //comment\n", 0) - assert_equal [java_lb, html_lb], Ohcount::parse(" <% //comment\n%>", "jsp") - end - - def test_comprehensive - verify_parse("jsp1.jsp") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'jsp', :comment).first) - assert_equal('/*comment*/', entities_array("", 'jsp', :comment).first) - assert_equal('//comment', entities_array("<%\n//comment\n%>", 'jsp', :comment).first) - assert_equal('/*comment*/', entities_array("<%\n/*comment*/\n%>", 'jsp', :comment).first) - end -end diff --git a/test/unit/license_sniffer_test.rb b/test/unit/license_sniffer_test.rb deleted file mode 100644 index afd4ded..0000000 --- a/test/unit/license_sniffer_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::LicensesSnifferTest < Ohcount::Test - - # To make test creation easy & straighforward, we use a - # file-based convention, as follows: - # - # test/src_licenses/_t1.c <-- a 'C' file - # containing - # - # test/expected_licences/_t1 <-- a text file containg - # space-delimited list of - # expected licenses - # - # This test loops over every file in the src_licenses directory ensuring - # the expected results are achieved. - # - def test_expected_licenses - src_dir = File.dirname(__FILE__) + "/../src_licenses" - expected_dir = File.dirname(__FILE__) + "/../expected_licenses" - - Dir.entries(src_dir).each do |f| - filename = src_dir + "/" + f - next if File.directory?(filename) - next if f[0..0] == "." - detected_licenses = LicenseSniffer.licenses_from_source_code(filename) - - # expected_licenses - begin - f =~ /^([^\.]*)/ - expected_filename = $1 - expected_licenses = File.new(expected_dir + "/" + expected_filename).read.split.collect { |l| l.intern } - rescue - case $! - when Errno::ENOENT - assert false, "Missing expected_licenses file for #{ f }" - end - end - - # match? - assert_equal expected_licenses, detected_licenses, "Mismatch in file #{ f }" - end - end - -end - diff --git a/test/unit/license_test.h b/test/unit/license_test.h new file mode 100644 index 0000000..8977e8f --- /dev/null +++ b/test/unit/license_test.h @@ -0,0 +1,77 @@ +// license_test.h written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include +#include +#include +#include + +#include "../../src/licenses.h" + +void src_vs_expected_tests() { + const char *src_licenses = "../src_licenses/"; + char src[FILENAME_MAX]; + strncpy(src, src_licenses, strlen(src_licenses)); + char *s_p = src + strlen(src_licenses); + + const char *expected_licenses = "../expected_licenses/"; + char expected[FILENAME_MAX]; + strncpy(expected, expected_licenses, strlen(expected_licenses)); + char *e_p = expected + strlen(expected_licenses); + + struct dirent *file; + DIR *d = opendir(src_licenses); + if (d) { + while ((file = readdir(d))) { + if (strcmp((const char *)file->d_name, ".") != 0 && + strcmp((const char *)file->d_name, "..") != 0) { + char *p; + int length; + + length = strlen(file->d_name); + strncpy(s_p, (const char *)file->d_name, length); + *(s_p + length) = '\0'; + + p = file->d_name + length; + while (*p != '.' && p > file->d_name) p--; + length = p - file->d_name; + strncpy(e_p, (const char *)file->d_name, length); + *(e_p + length) = '\0'; + FILE *f = fopen((const char *)expected, "rb"); + if (f) { + SourceFile *sf = ohcount_sourcefile_new((const char *)src); + LicenseList *iter = ohcount_sourcefile_get_license_list(sf)->head; + char line[40]; // max license name size + for (; fgets(line, sizeof(line), f); iter = iter->next) { + p = strstr(line, "\r"); + if (p == NULL) p = strstr(line, "\n"); + if (p) *p = '\0'; + assert(iter->lic->name); + assert(strcmp(line, iter->lic->name) == 0); + } + fclose(f); + ohcount_sourcefile_free(sf); + } + } + } + closedir(d); + } +} + +void very_long_file_test() { + int len = 5500000; + char *a = malloc(len); + memset(a, 'i', len); + a[len-1] = '\0'; + a[len-2] = '\n'; + + SourceFile *sf = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(sf, a); + strncpy(a, "int = 1;\n", strlen("int = 1;\n")); + ohcount_sourcefile_get_license_list(sf); +} + +void all_license_tests() { + src_vs_expected_tests(); + very_long_file_test(); +} diff --git a/test/unit/lisp_test.rb b/test/unit/lisp_test.rb deleted file mode 100644 index 14c8db7..0000000 --- a/test/unit/lisp_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::LispTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("lisp", "", ";;; comment", 0)] - assert_equal lb, Ohcount::parse(" ;;; comment", "lisp") - end - - def test_doc_string - lb = [Ohcount::LanguageBreakdown.new("lisp", "", '""" comment """', 0)] - assert_equal lb, Ohcount::parse(' """ comment """', "lisp") - end - - def test_doc_string_blank - lb = [Ohcount::LanguageBreakdown.new("lisp", "", '""""""', 0)] - assert_equal lb, Ohcount::parse(' """"""', "lisp") - end - - def test_empty_string - lb = [Ohcount::LanguageBreakdown.new("lisp", '""', "", 0)] - assert_equal lb, Ohcount::parse(' ""', "lisp") - end - - def test_char_string - lb = [Ohcount::LanguageBreakdown.new("lisp", '"a"', "", 0)] - assert_equal lb, Ohcount::parse(' "a"', "lisp") - end - - def test_comprehensive - verify_parse("lsp1.lsp") - end - - def test_comment_entities - assert_equal(';comment', entities_array(" ;comment", 'lisp', :comment).first) - end - -end diff --git a/test/unit/loc_test.h b/test/unit/loc_test.h new file mode 100644 index 0000000..abdb013 --- /dev/null +++ b/test/unit/loc_test.h @@ -0,0 +1,407 @@ +// loc_test.h written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include +#include +#include + +#include "../../src/loc.h" + +void test_loc_default() { + Loc *loc = ohcount_loc_new("c", 0, 0, 0, 0); + assert(strcmp("c", loc->language) == 0); + assert(loc->code == 0); + assert(loc->comments == 0); + assert(loc->blanks == 0); + assert(loc->filecount == 0); + ohcount_loc_free(loc); +} + +void test_loc_initializer() { + Loc *loc = ohcount_loc_new("c", 1, 2, 3, 4); + assert(strcmp("c", loc->language) == 0); + assert(loc->code == 1); + assert(loc->comments == 2); + assert(loc->blanks == 3); + assert(loc->filecount == 4); + ohcount_loc_free(loc); +} + +void test_loc_add() { + Loc *loc = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *loc2 = ohcount_loc_new("c", 10, 20, 30, 40); + ohcount_loc_add_loc(loc, loc2); + assert(strcmp("c", loc->language) == 0); + assert(loc->code == 11); + assert(loc->comments == 22); + assert(loc->blanks == 33); + assert(ohcount_loc_total(loc) == 66); + assert(loc->filecount == 44); + ohcount_loc_free(loc); + ohcount_loc_free(loc2); +} + +void test_loc_add_requires_same_language() { + Loc *loc = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *loc2 = ohcount_loc_new("java", 10, 20, 30, 40); + ohcount_loc_add_loc(loc, loc2); + assert(strcmp("c", loc->language) == 0); + assert(loc->code == 1); + assert(loc->comments == 2); + assert(loc->blanks == 3); + assert(loc->filecount == 4); + ohcount_loc_free(loc); + ohcount_loc_free(loc2); +} + +void test_loc_list_default() { + LocList *list = ohcount_loc_list_new(); + assert(list->loc == NULL); + ohcount_loc_list_free(list); +} + +void test_loc_list_selector() { + LocList *list = ohcount_loc_list_new(); + Loc *c = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *java = ohcount_loc_new("java", 10, 20, 30, 40); + ohcount_loc_list_add_loc(list, c); + ohcount_loc_list_add_loc(list, java); + assert(strcmp(list->head->loc->language, "c") == 0); + assert(strcmp(list->head->next->loc->language, "java") == 0); + assert(ohcount_loc_is_equal(ohcount_loc_list_get_loc(list, "c"), c)); + assert(ohcount_loc_is_equal(ohcount_loc_list_get_loc(list, "java"), java)); + ohcount_loc_free(c); + ohcount_loc_free(java); + ohcount_loc_list_free(list); +} + +void test_loc_list_first_add() { + LocList *list = ohcount_loc_list_new(); + Loc *c = ohcount_loc_new("c", 1, 2, 3, 4); + ohcount_loc_list_add_loc(list, c); + assert(ohcount_loc_is_equal(list->head->loc, c)); + assert(strcmp(list->head->loc->language, "c") == 0); + assert(ohcount_loc_list_code(list) == 1); + assert(ohcount_loc_list_comments(list) == 2); + assert(ohcount_loc_list_blanks(list) == 3); + assert(ohcount_loc_list_total(list) == 6); + assert(ohcount_loc_list_filecount(list) == 4); + ohcount_loc_free(c); + ohcount_loc_list_free(list); +} + +void test_loc_list_add_two_languages() { + LocList *list = ohcount_loc_list_new(); + Loc *c = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *java = ohcount_loc_new("java", 10, 20, 30, 40); + ohcount_loc_list_add_loc(list, c); + ohcount_loc_list_add_loc(list, java); + assert(strcmp(list->head->loc->language, "c") == 0); + assert(strcmp(list->head->next->loc->language, "java") == 0); + assert(ohcount_loc_is_equal(ohcount_loc_list_get_loc(list, "c"), c)); + assert(ohcount_loc_is_equal(ohcount_loc_list_get_loc(list, "java"), java)); + assert(ohcount_loc_list_code(list) == 11); + assert(ohcount_loc_list_comments(list) == 22); + assert(ohcount_loc_list_blanks(list) == 33); + assert(ohcount_loc_list_total(list) == 66); + assert(ohcount_loc_list_filecount(list) == 44); + ohcount_loc_free(c); + ohcount_loc_free(java); + ohcount_loc_list_free(list); +} + +void test_loc_list_add_same_language_twice() { + LocList *list = ohcount_loc_list_new(); + Loc *c1 = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *c2 = ohcount_loc_new("c", 10, 20, 30, 40); + ohcount_loc_list_add_loc(list, c1); + ohcount_loc_list_add_loc(list, c2); + assert(strcmp(list->head->loc->language, "c") == 0); + assert(list->head->next == NULL); + assert(ohcount_loc_list_code(list) == 11); + assert(ohcount_loc_list_comments(list) == 22); + assert(ohcount_loc_list_blanks(list) == 33); + assert(ohcount_loc_list_total(list) == 66); + assert(ohcount_loc_list_filecount(list) == 44); + ohcount_loc_free(c1); + ohcount_loc_free(c2); + ohcount_loc_list_free(list); +} + +void test_loc_list_add_loc_lists() { + LocList *list1 = ohcount_loc_list_new(); + LocList *list2 = ohcount_loc_list_new(); + Loc *c1 = ohcount_loc_new("c", 1, 0, 0, 0); + Loc *java = ohcount_loc_new("java", 2, 0, 0, 0); + Loc *c2 = ohcount_loc_new("c", 10, 0, 0, 0); + Loc *ruby = ohcount_loc_new("ruby", 3, 0, 0, 0); + ohcount_loc_list_add_loc(list1, c1); + ohcount_loc_list_add_loc(list1, java); + ohcount_loc_list_add_loc(list2, c2); + ohcount_loc_list_add_loc(list2, ruby); + ohcount_loc_list_add_loc_list(list1, list2); + assert(strcmp(list1->head->loc->language, "c") == 0); + assert(strcmp(list1->head->next->loc->language, "java") == 0); + assert(strcmp(list1->head->next->next->loc->language, "ruby") == 0); + assert(list1->head->next->next->next == NULL); + assert(ohcount_loc_list_get_loc(list1, "c")->code == 11); + assert(ohcount_loc_list_get_loc(list1, "java")->code == 2); + assert(ohcount_loc_list_get_loc(list1, "ruby")->code == 3); + assert(ohcount_loc_list_code(list1) == 16); + ohcount_loc_free(c1); + ohcount_loc_free(java); + ohcount_loc_free(c2); + ohcount_loc_free(ruby); + ohcount_loc_list_free(list1); + ohcount_loc_list_free(list2); +} + +void test_loc_list_compact() { + LocList *list = ohcount_loc_list_new(); + Loc *c = ohcount_loc_new("c", 1, 2, 3, 4); + Loc *java = ohcount_loc_new("java", 0, 0, 0, 0); + ohcount_loc_list_add_loc(list, c); + ohcount_loc_list_add_loc(list, java); + LocList *compacted = ohcount_loc_list_new_compact(list); + assert(ohcount_loc_is_equal(ohcount_loc_list_get_loc(compacted, "c"), c)); + assert(compacted->head->next == NULL); + ohcount_loc_free(c); + ohcount_loc_free(java); + ohcount_loc_list_free(list); + ohcount_loc_list_free(compacted); +} + +void test_loc_delta_default() { + LocDelta *delta = ohcount_loc_delta_new("c", 0, 0, 0, 0, 0, 0); + assert(delta->code_added == 0); + assert(delta->code_removed == 0); + assert(delta->comments_added == 0); + assert(delta->comments_removed == 0); + assert(delta->blanks_added == 0); + assert(delta->blanks_removed == 0); + ohcount_loc_delta_free(delta); +} + +void test_loc_delta_initializer() { + LocDelta *delta = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + assert(strcmp(delta->language, "c") == 0); + assert(delta->code_added == 1); + assert(delta->code_removed == 10); + assert(delta->comments_added == 2); + assert(delta->comments_removed == 20); + assert(delta->blanks_added == 3); + assert(delta->blanks_removed == 30); + ohcount_loc_delta_free(delta); +} + +void test_loc_delta_net_total() { + LocDelta *delta = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + assert(ohcount_loc_delta_net_code(delta) == -9); + assert(ohcount_loc_delta_net_comments(delta) == -18); + assert(ohcount_loc_delta_net_blanks(delta) == -27); + assert(ohcount_loc_delta_net_total(delta) == -54); + ohcount_loc_delta_free(delta); +} + +void test_loc_delta_addition() { + LocDelta *delta1 = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *delta2 = ohcount_loc_delta_new("c", 100, 1000, 200, 2000, 300, + 3000); + ohcount_loc_delta_add_loc_delta(delta1, delta2); + assert(delta1->code_added == 101); + assert(delta1->code_removed == 1010); + assert(delta1->comments_added == 202); + assert(delta1->comments_removed == 2020); + assert(delta1->blanks_added == 303); + assert(delta1->blanks_removed == 3030); + ohcount_loc_delta_free(delta1); + ohcount_loc_delta_free(delta2); +} + +void test_loc_delta_addition_requires_matching_language() { + LocDelta *delta1 = ohcount_loc_delta_new("c", 0, 0, 0, 0, 0, 0); + LocDelta *delta2 = ohcount_loc_delta_new("java", 1, 10, 2, 20, 3, 30); + ohcount_loc_delta_add_loc_delta(delta1, delta2); + assert(strcmp(delta1->language, "c") == 0); + assert(delta1->code_added == 0); + assert(delta1->code_removed == 0); + assert(delta1->comments_added == 0); + assert(delta1->comments_removed == 0); + assert(delta1->blanks_added == 0); + assert(delta1->blanks_removed == 0); + ohcount_loc_delta_free(delta1); + ohcount_loc_delta_free(delta2); +} + +void test_loc_delta_equals() { + LocDelta *delta1 = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *delta2 = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + ohcount_loc_delta_free(delta1); + ohcount_loc_delta_free(delta2); +} + +void test_loc_delta_list_default() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + assert(list->delta == NULL); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_selector() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c = ohcount_loc_delta_new("c", 0, 0, 0, 0, 0, 0); + LocDelta *java = ohcount_loc_delta_new("java", 0, 0, 0, 0, 0, 0); + ohcount_loc_delta_list_add_loc_delta(list, c); + ohcount_loc_delta_list_add_loc_delta(list, java); + assert(ohcount_loc_delta_is_equal( + ohcount_loc_delta_list_get_loc_delta(list, "c"), c)); + assert(ohcount_loc_delta_is_equal( + ohcount_loc_delta_list_get_loc_delta(list, "java"), java)); + ohcount_loc_delta_free(c); + ohcount_loc_delta_free(java); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_first_add() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + ohcount_loc_delta_list_add_loc_delta(list, c); + assert(strcmp(list->head->delta->language, "c") == 0); + assert(ohcount_loc_delta_list_code_added(list) == 1); + assert(ohcount_loc_delta_list_code_removed(list) == 10); + assert(ohcount_loc_delta_list_comments_added(list) == 2); + assert(ohcount_loc_delta_list_comments_removed(list) == 20); + assert(ohcount_loc_delta_list_blanks_added(list) == 3); + assert(ohcount_loc_delta_list_blanks_removed(list) == 30); + ohcount_loc_delta_free(c); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_add_two_languages() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *java = ohcount_loc_delta_new("java", 100, 1000, 200, 2000, 300, + 3000); + ohcount_loc_delta_list_add_loc_delta(list, c); + ohcount_loc_delta_list_add_loc_delta(list, java); + assert(ohcount_loc_delta_is_equal( + ohcount_loc_delta_list_get_loc_delta(list, "c"), c)); + assert(ohcount_loc_delta_is_equal( + ohcount_loc_delta_list_get_loc_delta(list, "java"), java)); + assert(strcmp(list->head->delta->language, "c") == 0); + assert(strcmp(list->head->next->delta->language, "java") == 0); + assert(ohcount_loc_delta_list_code_added(list) == 101); + assert(ohcount_loc_delta_list_code_removed(list) == 1010); + assert(ohcount_loc_delta_list_comments_added(list) == 202); + assert(ohcount_loc_delta_list_comments_removed(list) == 2020); + assert(ohcount_loc_delta_list_blanks_added(list) == 303); + assert(ohcount_loc_delta_list_blanks_removed(list) == 3030); + ohcount_loc_delta_free(c); + ohcount_loc_delta_free(java); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_add_same_language_twice() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c1 = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *c2 = ohcount_loc_delta_new("c", 100, 1000, 200, 2000, 300, 3000); + ohcount_loc_delta_list_add_loc_delta(list, c1); + ohcount_loc_delta_list_add_loc_delta(list, c2); + assert(list->head->next == NULL); + assert(strcmp(list->head->delta->language, "c") == 0); + assert(ohcount_loc_delta_list_code_added(list) == 101); + assert(ohcount_loc_delta_list_code_removed(list) == 1010); + assert(ohcount_loc_delta_list_comments_added(list) == 202); + assert(ohcount_loc_delta_list_comments_removed(list) == 2020); + assert(ohcount_loc_delta_list_blanks_added(list) == 303); + assert(ohcount_loc_delta_list_blanks_removed(list) == 3030); + ohcount_loc_delta_free(c1); + ohcount_loc_delta_free(c2); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_add_two_lists() { + LocDeltaList *list1 = ohcount_loc_delta_list_new(); + LocDeltaList *list2 = ohcount_loc_delta_list_new(); + LocDelta *c1 = ohcount_loc_delta_new("c", 0, 0, 0, 0, 0, 0); + LocDelta *c2 = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + ohcount_loc_delta_list_add_loc_delta(list1, c1); + ohcount_loc_delta_list_add_loc_delta(list2, c2); + ohcount_loc_delta_list_add_loc_delta_list(list1, list2); + assert(ohcount_loc_delta_list_code_added(list1) == 1); + assert(ohcount_loc_delta_list_code_removed(list1) == 10); + assert(ohcount_loc_delta_list_comments_added(list1) == 2); + assert(ohcount_loc_delta_list_comments_removed(list1) == 20); + assert(ohcount_loc_delta_list_blanks_added(list1) == 3); + assert(ohcount_loc_delta_list_blanks_removed(list1) == 30); + ohcount_loc_delta_free(c1); + ohcount_loc_delta_free(c2); + ohcount_loc_delta_list_free(list1); + ohcount_loc_delta_list_free(list2); +} + +void test_loc_delta_list_net_total() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *java = ohcount_loc_delta_new("java", 100, 1000, 200, 2000, 300, + 3000); + ohcount_loc_delta_list_add_loc_delta(list, c); + ohcount_loc_delta_list_add_loc_delta(list, java); + assert(ohcount_loc_delta_list_net_code(list) == 1 - 10 + 100 - 1000); + assert(ohcount_loc_delta_list_net_comments(list) == 2 - 20 + 200 - 2000); + assert(ohcount_loc_delta_list_net_blanks(list) == 3 - 30 + 300 - 3000); + assert(ohcount_loc_delta_list_net_total(list) == 6 - 60 + 600 - 6000); + ohcount_loc_delta_free(c); + ohcount_loc_delta_free(java); + ohcount_loc_delta_list_free(list); +} + +void test_loc_delta_list_compact() { + LocDeltaList *list = ohcount_loc_delta_list_new(); + LocDelta *c = ohcount_loc_delta_new("c", 1, 10, 2, 20, 3, 30); + LocDelta *ruby = ohcount_loc_delta_new("ruby", 1, 1, 0, 0, 0, 0); + LocDelta *java = ohcount_loc_delta_new("java", 0, 0, 0, 0, 0, 0); + ohcount_loc_delta_list_add_loc_delta(list, c); + ohcount_loc_delta_list_add_loc_delta(list, ruby); + ohcount_loc_delta_list_add_loc_delta(list, java); + LocDeltaList *compacted = ohcount_loc_delta_list_new_compact(list); + assert(ohcount_loc_delta_is_equal(ohcount_loc_delta_list_get_loc_delta(compacted, "c"), c)); + assert(ohcount_loc_delta_is_equal(ohcount_loc_delta_list_get_loc_delta(compacted, "ruby"), ruby)); + assert(compacted->head->next->next == NULL); + ohcount_loc_delta_free(c); + ohcount_loc_delta_free(ruby); + ohcount_loc_delta_free(java); + ohcount_loc_delta_list_free(list); + ohcount_loc_delta_list_free(compacted); +} + +void all_loc_tests() { + test_loc_default(); + test_loc_initializer(); + test_loc_add(); + test_loc_add_requires_same_language(); + + test_loc_list_default(); + test_loc_list_selector(); + test_loc_list_first_add(); + test_loc_list_add_two_languages(); + test_loc_list_add_same_language_twice(); + test_loc_list_add_loc_lists(); + test_loc_list_compact(); + + test_loc_delta_default(); + test_loc_delta_initializer(); + test_loc_delta_net_total(); + test_loc_delta_addition(); + test_loc_delta_addition_requires_matching_language(); + test_loc_delta_equals(); + + test_loc_delta_list_default(); + test_loc_delta_list_selector(); + test_loc_delta_list_first_add(); + test_loc_delta_list_add_two_languages(); + test_loc_delta_list_add_same_language_twice(); + test_loc_delta_list_add_two_lists(); + test_loc_delta_list_net_total(); + test_loc_delta_list_compact(); +} diff --git a/test/unit/lua_test.rb b/test/unit/lua_test.rb deleted file mode 100644 index cec949c..0000000 --- a/test/unit/lua_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::LuaTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("lua", "", "-- comment", 0)] - assert_equal lb, Ohcount::parse(" -- comment", "lua") - end - - def test_comprehensive - verify_parse("lua1.lua") - end - - def test_comment_entities - assert_equal('--comment', entities_array(" --comment", 'lua', :comment).first) - assert_equal("--[[comment\ncomment]]", entities_array(" --[[comment\ncomment]]", 'lua', :comment).first) - end - -end diff --git a/test/unit/make_test.rb b/test/unit/make_test.rb deleted file mode 100644 index 12461c2..0000000 --- a/test/unit/make_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::MakefileTest < Ohcount::Test - def test_comprehensive - verify_parse("Makefile") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'make', :comment).first) - end - -end - diff --git a/test/unit/matlab_test.rb b/test/unit/matlab_test.rb deleted file mode 100644 index dd140da..0000000 --- a/test/unit/matlab_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::MatlabTest < Ohcount::Test - - def test_line_comment_1 - lb = [Ohcount::LanguageBreakdown.new("matlab", "", "%comment", 0)] - assert_equal lb, Ohcount::parse(" %comment", "matlab") - end - - def test_octave_syntax_comment - lb = [Ohcount::LanguageBreakdown.new("matlab", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "matlab") - end - - def test_false_line_comment - lb = [Ohcount::LanguageBreakdown.new("matlab", "%{block%} code", "", 0)] - assert_equal lb, Ohcount::parse(" %{block%} code", "matlab") - end - - def test_comprehensive - verify_parse("matlab1.m", 'matlab') - end - - def test_comment_entities - assert_equal('%comment', entities_array(" %comment", 'matlab', :comment).first) - assert_equal('#comment', entities_array(" #comment", 'matlab', :comment).first) - assert_equal('%{comment%}', entities_array(" %{comment%}", 'matlab', :comment).first) - end - -end diff --git a/test/unit/metafont_test.rb b/test/unit/metafont_test.rb deleted file mode 100644 index 890f27c..0000000 --- a/test/unit/metafont_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::MetaFontTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("metafont", "", "% comment", 0)] - assert_equal lb, Ohcount::parse(" % comment", "metafont") - end - - def test_comprehensive - verify_parse("metafont.mf") - end - - def test_comment_entities - assert_equal('%comment', entities_array(" %comment", 'metafont', :comment).first) - end -end diff --git a/test/unit/metapost_test.rb b/test/unit/metapost_test.rb deleted file mode 100644 index 113141c..0000000 --- a/test/unit/metapost_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::MetaPostTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("metapost", "", "% comment", 0)] - assert_equal lb, Ohcount::parse(" % comment", "metapost") - end - - def test_comprehensive - verify_parse("metapost.mp") - end - - def test_comment_entities - assert_equal('%comment', entities_array(" %comment", 'metapost', :comment).first) - assert_equal('%comment', entities_array("verbatim\n%comment\netex", 'metapost', :comment).first) - end -end diff --git a/test/unit/mxml_test.rb b/test/unit/mxml_test.rb deleted file mode 100644 index da69ebc..0000000 --- a/test/unit/mxml_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::MxmlTest < Ohcount::Test - def test_comprehensive - verify_parse("mxml1.mxml") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'mxml', :comment).first) - assert_equal('/*comment*/', entities_array("\n/*comment*/\n", 'mxml', :comment).first) - assert_equal('//comment', entities_array("\n//comment\n", 'mxml', :comment).first) - assert_equal('/*comment*/', entities_array("\n/*comment*/\n", 'mxml', :comment).first) - end -end diff --git a/test/unit/ocaml_test.rb b/test/unit/ocaml_test.rb deleted file mode 100644 index 2035b97..0000000 --- a/test/unit/ocaml_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::OcamlTest < Ohcount::Test - def test_regular_comments - lb = [Ohcount::LanguageBreakdown.new("ocaml", "", "(* comment *)", 0)] - assert_equal lb, Ohcount::parse(" (* comment *)", "ocaml") - end - - def test_comprehensive - verify_parse("ocaml.ml") - end - - def test_comment_entities - assert_equal('(*comment*)', entities_array(" (*comment*)", 'ocaml', :comment).first) - end - -end diff --git a/test/unit/parser_test.h b/test/unit/parser_test.h new file mode 100644 index 0000000..bda1c0d --- /dev/null +++ b/test/unit/parser_test.h @@ -0,0 +1,349 @@ +// parser_test.h written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include +#include +#include +#include +#include + +#include "../../src/sourcefile.h" + +SourceFile *test_parser_sourcefile(const char *language, const char *contents) { + SourceFile *sf = ohcount_sourcefile_new("foo"); + ohcount_sourcefile_set_contents(sf, contents); + ohcount_sourcefile_set_language(sf, language); + return sf; +} + +void test_parser_verify_parse(SourceFile *sf, const char *language, + const char *code, const char *comments, + int blanks) { + ohcount_sourcefile_parse(sf); + ParsedLanguageList *list = ohcount_sourcefile_get_parsed_language_list(sf); + assert(strcmp(list->head->pl->name, language) == 0); + assert(strcmp(list->head->pl->code, code) == 0); + assert(strcmp(list->head->pl->comments, comments) == 0); + assert(list->head->pl->blanks_count == blanks); + ohcount_sourcefile_free(sf); +} + +void test_parser_verify_parse2(SourceFile *sf, const char *language, + const char *code, const char *comments, + int blanks, const char *language2, + const char *code2, const char *comments2, + int blanks2) { + ohcount_sourcefile_parse(sf); + ParsedLanguageList *list = ohcount_sourcefile_get_parsed_language_list(sf); + assert(strcmp(list->head->pl->name, language) == 0); + assert(strcmp(list->head->pl->code, code) == 0); + assert(strcmp(list->head->pl->comments, comments) == 0); + assert(list->head->pl->blanks_count == blanks); + assert(strcmp(list->head->next->pl->name, language2) == 0); + assert(strcmp(list->head->next->pl->code, code2) == 0); + assert(strcmp(list->head->next->pl->comments, comments2) == 0); + assert(list->head->next->pl->blanks_count == blanks2); + ohcount_sourcefile_free(sf); +} + +typedef struct { + SourceFile *sf; + const char *entity; + const char *expected; +} TestParserEntityUData; + +void test_parser_entity_callback(const char *language, const char *entity, + int start, int end, void *userdata) { + TestParserEntityUData *udata = (TestParserEntityUData *)userdata; + if (strcmp(entity, udata->entity) == 0) { + char *buffer = ohcount_sourcefile_get_contents(udata->sf); + assert(strncmp(udata->expected, buffer + start, end - start) == 0); + } +} + +void test_parser_verify_entity(SourceFile *sf, const char *entity, + const char *expected) { + TestParserEntityUData *udata = malloc(sizeof(TestParserEntityUData)); + udata->sf = sf; + udata->entity = entity; + udata->expected = expected; + ohcount_sourcefile_parse_entities_with_callback(sf, + test_parser_entity_callback, udata); + ohcount_sourcefile_free(sf); + free(udata); +} + +#include "parsers/test_actionscript.h" +#include "parsers/test_ada.h" +#include "parsers/test_ampl.h" +#include "parsers/test_assembler.h" +#include "parsers/test_augeas.h" +#include "parsers/test_autoconf.h" +#include "parsers/test_automake.h" +#include "parsers/test_awk.h" +#include "parsers/test_basic.h" +#include "parsers/test_bat.h" +#include "parsers/test_blitzmax.h" +#include "parsers/test_boo.h" +#include "parsers/test_brainfuck.h" +#include "parsers/test_bfpp.h" +#include "parsers/test_c.h" +#include "parsers/test_chaiscript.h" +#include "parsers/test_clearsilvertemplate.h" +#include "parsers/test_clearsilver.h" +#include "parsers/test_clojure.h" +#include "parsers/test_coq.h" +#include "parsers/test_cs_aspx.h" +#include "parsers/test_csharp.h" +#include "parsers/test_css.h" +#include "parsers/test_d.h" +#include "parsers/test_dcl.h" +#include "parsers/test_dylan.h" +#include "parsers/test_ebuild.h" +#include "parsers/test_eiffel.h" +#include "parsers/test_emacs_lisp.h" +#include "parsers/test_erlang.h" +#include "parsers/test_exheres.h" +#include "parsers/test_factor.h" +#include "parsers/test_forth.h" +#include "parsers/test_fortran.h" +#include "parsers/test_fsharp.h" +#include "parsers/test_glsl.h" +#include "parsers/test_golang.h" +#include "parsers/test_groovy.h" +#include "parsers/test_haml.h" +#include "parsers/test_haskell.h" +#include "parsers/test_haxe.h" +#include "parsers/test_html.h" +#include "parsers/test_idl_pvwave.h" +#include "parsers/test_jam.h" +#include "parsers/test_java.h" +#include "parsers/test_javascript.h" +#include "parsers/test_jsp.h" +#include "parsers/test_lisp.h" +#include "parsers/test_logtalk.h" +#include "parsers/test_lua.h" +#include "parsers/test_make.h" +#include "parsers/test_mathematica.h" +#include "parsers/test_matlab.h" +#include "parsers/test_metafont.h" +#include "parsers/test_metapost.h" +#include "parsers/test_mxml.h" +#include "parsers/test_nix.h" +#include "parsers/test_nsis.h" +#include "parsers/test_objective_j.h" +#include "parsers/test_ocaml.h" +#include "parsers/test_octave.h" +#include "parsers/test_pascal.h" +#include "parsers/test_perl.h" +#include "parsers/test_pike.h" +#include "parsers/test_puppet.h" +#include "parsers/test_python.h" +#include "parsers/test_qml.h" +#include "parsers/test_r.h" +#include "parsers/test_racket.h" +#include "parsers/test_rebol.h" +#include "parsers/test_rexx.h" +#include "parsers/test_rhtml.h" +#include "parsers/test_ruby.h" +#include "parsers/test_scala.h" +#include "parsers/test_scheme.h" +#include "parsers/test_scilab.h" +#include "parsers/test_shell.h" +#include "parsers/test_smalltalk.h" +#include "parsers/test_sql.h" +#include "parsers/test_stratego.h" +#include "parsers/test_tcl.h" +#include "parsers/test_tex.h" +#include "parsers/test_vala.h" +#include "parsers/test_vb_aspx.h" +#include "parsers/test_vhdl.h" +#include "parsers/test_visualbasic.h" +#include "parsers/test_xaml.h" +#include "parsers/test_xml.h" +#include "parsers/test_xmlschema.h" +#include "parsers/test_xslt.h" + +typedef struct { + SourceFile *sf; + FILE *f; +} TestParserUData; + +void test_parser_callback(const char *language, const char *entity, + int start, int end, void *userdata) { + TestParserUData *udata = (TestParserUData *)userdata; + char line[512], line2[512]; + assert(fgets(line, sizeof(line), udata->f) != NULL); + if (strcmp(entity, "lcode") == 0) + entity = "code"; + else if (strcmp(entity, "lcomment") == 0) + entity = "comment"; + else if (strcmp(entity, "lblank") == 0) + entity = "blank"; + sprintf(line2, "%s\t%s\t", language, entity); + char *buffer = ohcount_sourcefile_get_contents(udata->sf); + strncpy(line2 + strlen(language) + strlen(entity) + 2, buffer + start, + end - start); + line2[strlen(language) + strlen(entity) + 2 + (end - start)] = '\0'; + if (strcmp(line, line2) != 0) { + fprintf(stderr, "FAIL: Parser test failure in %s:\nExpected: %sGot: %s", udata->sf->filename, line, line2); + assert(strcmp(line, line2) == 0); + } +} + +char *test_parser_filenames[] = { "", 0 }; + +void test_parser_verify_parses() { + const char *src_dir = "../src_dir/"; + char src[FILENAME_MAX]; + strncpy(src, src_dir, strlen(src_dir)); + char *s_p = src + strlen(src_dir); + + const char *expected_dir = "../expected_dir/"; + char expected[FILENAME_MAX]; + strncpy(expected, expected_dir, strlen(expected_dir)); + char *e_p = expected + strlen(expected_dir); + + struct dirent *file; + DIR *d = opendir(src_dir); + if (d) { + while ((file = readdir(d))) { + if (strcmp((const char *)file->d_name, ".") != 0 && + strcmp((const char *)file->d_name, "..") != 0) { + int length = strlen(file->d_name); + strncpy(s_p, (const char *)file->d_name, length); + *(s_p + length) = '\0'; + strncpy(e_p, (const char *)file->d_name, length); + *(e_p + length) = '\0'; + + FILE *f = fopen((const char *)expected, "rb"); + if (f) { + SourceFile *sf = ohcount_sourcefile_new((const char *)src); + + // Disambiguators in the detector may access the directory contents of + // the file in question. This could lead to mis-detections for these + // unit tests. By default the directory contents are set to "". If + // this is not desired, add your cases here. + if (strcmp(s_p, "visual_basic.bas") == 0) + // This file needs frx1.frx in the directory contents to be + // detected as Visual Basic. + sf->filenames = test_basic_vb_filenames; + else + sf->filenames = test_parser_filenames; + + TestParserUData *udata = malloc(sizeof(TestParserUData)); + udata->sf = sf; + udata->f = f; + + // If the expected file not empty, then the source file should be + // detected as something. Un-detected files are not parsed so no + // failing assertions would be made, resulting in erroneously passed + // tests. + const char *language = ohcount_sourcefile_get_language(sf); + fseek(f, 0, SEEK_END); + if (ftell(f) > 0) + assert(language); + rewind(f); + + ohcount_sourcefile_parse_with_callback(sf, test_parser_callback, + (void *)udata); + fclose(f); + ohcount_sourcefile_free(sf); + free(udata); + } + } + } + closedir(d); + } +} + +void all_parser_tests() { + test_parser_verify_parses(); + all_actionscript_tests(); + all_ada_tests(); + all_ampl_tests(); + all_assembler_tests(); + all_augeas_tests(); + all_autoconf_tests(); + all_automake_tests(); + all_awk_tests(); + all_basic_tests(); + all_bat_tests(); + all_blitzmax_tests(); + all_boo_tests(); + all_brainfuck_tests(); + all_bfpp_tests(); + all_c_tests(); + all_chaiscript_tests(); + all_clearsilver_template_tests(); + all_clearsilver_tests(); + all_clojure_tests(); + all_coq_tests(); + all_cs_aspx_tests(); + all_csharp_tests(); + all_css_tests(); + all_dmd_tests(); + all_dcl_tests(); + all_dylan_tests(); + all_ebuild_tests(); + all_eiffel_tests(); + all_emacs_lisp_tests(); + all_erlang_tests(); + all_exheres_tests(); + all_factor_tests(); + all_forth_tests(); + all_fortran_tests(); + all_fsharp_tests(); + all_glsl_tests(); + all_groovy_tests(); + all_haml_tests(); + all_haskell_tests(); + all_haxe_tests(); + all_html_tests(); + all_idl_pvwave_tests(); + all_jam_tests(); + all_java_tests(); + all_javascript_tests(); + all_jsp_tests(); + all_lisp_tests(); + all_logtalk_tests(); + all_lua_tests(); + all_make_tests(); + all_mathematica_tests(); + all_matlab_tests(); + all_metafont_tests(); + all_metapost_tests(); + all_mxml_tests(); + all_nix_tests(); + all_nsis_tests(); + all_objective_j_tests(); + all_ocaml_tests(); + all_octave_tests(); + all_pascal_tests(); + all_perl_tests(); + all_pike_tests(); + all_python_tests(); + all_r_tests(); + all_racket_tests(); + all_rebol_tests(); + all_rexx_tests(); + all_rhtml_tests(); + all_ruby_tests(); + all_scala_tests(); + all_scheme_tests(); + all_scilab_tests(); + all_shell_tests(); + all_smalltalk_tests(); + all_sql_tests(); + all_stratego_tests(); + all_tcl_tests(); + all_tex_tests(); + all_vala_tests(); + all_vb_aspx_tests(); + all_vhdl_tests(); + all_visualbasic_tests(); + all_xaml_tests(); + all_xml_tests(); + all_xmlschema_tests(); + all_xslt_tests(); +} diff --git a/test/unit/parsers/test_actionscript.h b/test/unit/parsers/test_actionscript.h new file mode 100644 index 0000000..cea8f48 --- /dev/null +++ b/test/unit/parsers/test_actionscript.h @@ -0,0 +1,23 @@ + +void test_actionscript_comments() { + test_parser_verify_parse( + test_parser_sourcefile("actionscript", " //comment"), + "actionscript", "", "//comment", 0 + ); +} + +void test_actionscript_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("actionscript", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("actionscript", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_actionscript_tests() { + test_actionscript_comments(); + test_actionscript_comment_entities(); +} diff --git a/test/unit/parsers/test_ada.h b/test/unit/parsers/test_ada.h new file mode 100644 index 0000000..dbbb03d --- /dev/null +++ b/test/unit/parsers/test_ada.h @@ -0,0 +1,19 @@ + +void test_ada_comments() { + test_parser_verify_parse( + test_parser_sourcefile("ada", " --comment"), + "ada", "", "--comment", 0 + ); +} + +void test_ada_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("ada", " --comment"), + "comment", "--comment" + ); +} + +void all_ada_tests() { + test_ada_comments(); + test_ada_comment_entities(); +} diff --git a/test/unit/parsers/test_ampl.h b/test/unit/parsers/test_ampl.h new file mode 100644 index 0000000..bcd028f --- /dev/null +++ b/test/unit/parsers/test_ampl.h @@ -0,0 +1,19 @@ + +void test_ampl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("ampl", " #comment"), + "ampl", "", "#comment", 0 + ); +} + +void test_ampl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("ampl", " #comment"), + "comment", "#comment" + ); +} + +void all_ampl_tests() { + test_ampl_comments(); + test_ampl_comment_entities(); +} diff --git a/test/unit/parsers/test_assembler.h b/test/unit/parsers/test_assembler.h new file mode 100644 index 0000000..c1c98a8 --- /dev/null +++ b/test/unit/parsers/test_assembler.h @@ -0,0 +1,27 @@ + +void test_assembler_comments() { + test_parser_verify_parse( + test_parser_sourcefile("assembler", " !comment\n ;comment"), + "assembler", "", "!comment\n;comment", 0 + ); +} + +void test_assembler_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("assembler", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("assembler", " ; comment"), + "comment", "; comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("assembler", " !comment"), + "comment", "!comment" + ); +} + +void all_assembler_tests() { + test_assembler_comments(); + test_assembler_comment_entities(); +} diff --git a/test/unit/parsers/test_augeas.h b/test/unit/parsers/test_augeas.h new file mode 100644 index 0000000..2e2e60a --- /dev/null +++ b/test/unit/parsers/test_augeas.h @@ -0,0 +1,19 @@ + +void test_augeas_comments() { + test_parser_verify_parse( + test_parser_sourcefile("augeas", " (* comment *)"), + "augeas", "", "(* comment *)", 0 + ); +} + +void test_augeas_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("augeas", " (*comment*)"), + "comment", "(*comment*)" + ); +} + +void all_augeas_tests() { + test_augeas_comments(); + test_augeas_comment_entities(); +} diff --git a/test/unit/parsers/test_autoconf.h b/test/unit/parsers/test_autoconf.h new file mode 100644 index 0000000..353f821 --- /dev/null +++ b/test/unit/parsers/test_autoconf.h @@ -0,0 +1,11 @@ + +void test_autoconf_comment_entities() { + test_parser_verify_parse( + test_parser_sourcefile("autoconf", " dnl comment"), + "autoconf", "", "dnl comment", 0 + ); +} + +void all_autoconf_tests() { + test_autoconf_comment_entities(); +} diff --git a/test/unit/parsers/test_automake.h b/test/unit/parsers/test_automake.h new file mode 100644 index 0000000..aa26675 --- /dev/null +++ b/test/unit/parsers/test_automake.h @@ -0,0 +1,11 @@ + +void test_automake_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("automake", " #comment"), + "comment", "#comment" + ); +} + +void all_automake_tests() { + test_automake_comment_entities(); +} diff --git a/test/unit/parsers/test_awk.h b/test/unit/parsers/test_awk.h new file mode 100644 index 0000000..fa25572 --- /dev/null +++ b/test/unit/parsers/test_awk.h @@ -0,0 +1,28 @@ + +void test_awk_comments() { + test_parser_verify_parse( + test_parser_sourcefile("awk", " #comment"), + "awk", "", "#comment", 0 + ); +} + +void test_awk_double_slash() { + test_parser_verify_parse( + test_parser_sourcefile("awk", "\"\\\\\"\n#comment"), + "awk", "\"\\\\\"\n", "#comment", 0 + ); + // awk doesn't recognize backslash escaping of double quote...weird +} + +void test_awk_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("awk", " #comment"), + "comment", "#comment" + ); +} + +void all_awk_tests() { + test_awk_comments(); + test_awk_double_slash(); + test_awk_comment_entities(); +} diff --git a/test/unit/parsers/test_basic.h b/test/unit/parsers/test_basic.h new file mode 100644 index 0000000..528f1fc --- /dev/null +++ b/test/unit/parsers/test_basic.h @@ -0,0 +1,33 @@ + +char *test_basic_vb_filenames[] = { "frx1.frx", 0 }; + +void test_basic_sb_comments() { + test_parser_verify_parse( + test_parser_sourcefile("structured_basic", " REM comment"), + "structured_basic", "", "REM comment", 0 + ); +} + +void test_basic_cb_comments() { + test_parser_verify_parse( + test_parser_sourcefile("classic_basic", " 100 REM comment"), + "classic_basic", "", "100 REM comment", 0 + ); +} + +void test_basic_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("structured_basic", " REM comment"), + "comment", "REM comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("classic_basic", " 'comment"), + "comment", "'comment" + ); +} + +void all_basic_tests() { + test_basic_sb_comments(); + test_basic_cb_comments(); + test_basic_comment_entities(); +} diff --git a/test/unit/parsers/test_bat.h b/test/unit/parsers/test_bat.h new file mode 100644 index 0000000..79518f1 --- /dev/null +++ b/test/unit/parsers/test_bat.h @@ -0,0 +1,19 @@ + +void test_bat_comments() { + test_parser_verify_parse( + test_parser_sourcefile("bat", " REM comment"), + "bat", "", "REM comment", 0 + ); +} + +void test_bat_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("bat", " rem comment"), + "comment", "rem comment" + ); +} + +void all_bat_tests() { + test_bat_comments(); + test_bat_comment_entities(); +} diff --git a/test/unit/parsers/test_bfpp.h b/test/unit/parsers/test_bfpp.h new file mode 100644 index 0000000..cef3077 --- /dev/null +++ b/test/unit/parsers/test_bfpp.h @@ -0,0 +1,19 @@ +void test_bfpp_comment() { + test_parser_verify_parse( + test_parser_sourcefile("bfpp", " = comment"), + "bfpp", "", "= comment", 0 + ); +} + +void test_bfpp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("bfpp", " = comment"), + " comment", "= comment" + ); +} + +void all_bfpp_tests() { + test_bfpp_comment(); + test_bfpp_comment_entities(); +} + diff --git a/test/unit/parsers/test_blitzmax.h b/test/unit/parsers/test_blitzmax.h new file mode 100644 index 0000000..ee72312 --- /dev/null +++ b/test/unit/parsers/test_blitzmax.h @@ -0,0 +1,19 @@ + +void test_blitzmax_comments() { + test_parser_verify_parse( + test_parser_sourcefile("blitzmax", "' comment"), + "blitzmax", "", "' comment", 0 + ); +} + +void test_blitzmax_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("bat", " ' comment"), + "comment", "' comment" + ); +} + +void all_blitzmax_tests() { + test_blitzmax_comments(); + test_blitzmax_comment_entities(); +} diff --git a/test/unit/parsers/test_boo.h b/test/unit/parsers/test_boo.h new file mode 100644 index 0000000..7b3201b --- /dev/null +++ b/test/unit/parsers/test_boo.h @@ -0,0 +1,55 @@ + +void test_boo_comment() { + test_parser_verify_parse( + test_parser_sourcefile("boo", " #comment"), + "boo", "", "#comment", 0 + ); +} + +void test_boo_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("boo", " /*comment*/"), + "boo", "", "/*comment*/", 0 + ); +} + +void test_boo_nested_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("boo", " /* comment\n /* nested */\nstill a comment */"), + "boo", "", "/* comment\n/* nested */\nstill a comment */", 0 + ); +} + +void test_boo_doc_comments() { + test_parser_verify_parse( + test_parser_sourcefile("boo", "\"\"\"\\ndoc comment\n\"\"\""), + "boo", "", "\"\"\"\\ndoc comment\n\"\"\"", 0 + ); +} + +void test_boo_strings() { + test_parser_verify_parse( + test_parser_sourcefile("boo", "\"abc#not a 'comment\""), + "boo", "\"abc#not a 'comment\"", "", 0 + ); +} + +void test_boo_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("boo", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("boo", " //comment"), + "comment", "//comment" + ); +} + +void all_boo_tests() { + test_boo_comment(); + test_boo_block_comment(); + test_boo_nested_block_comment(); + test_boo_doc_comments(); + test_boo_strings(); + test_boo_comment_entities(); +} diff --git a/test/unit/parsers/test_brainfuck.h b/test/unit/parsers/test_brainfuck.h new file mode 100644 index 0000000..a13f452 --- /dev/null +++ b/test/unit/parsers/test_brainfuck.h @@ -0,0 +1,18 @@ +void test_brainfuck_comment() { + test_parser_verify_parse( + test_parser_sourcefile("brainfuck", " #comment"), + "brainfuck", "", "#comment", 0 + ); +} + +void test_brainfuck_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("brainfuck", " #comment"), + "#comment", "#comment" + ); +} + +void all_brainfuck_tests() { + test_brainfuck_comment(); + test_brainfuck_comment_entities(); +} diff --git a/test/unit/parsers/test_c.h b/test/unit/parsers/test_c.h new file mode 100644 index 0000000..f8c03d1 --- /dev/null +++ b/test/unit/parsers/test_c.h @@ -0,0 +1,39 @@ + +void test_c_comments() { + test_parser_verify_parse( + test_parser_sourcefile("c", " //comment"), + "c", "", "//comment", 0 + ); +} + +void test_c_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("c", " //\n"), + "c", "", "//\n", 0 + ); +} + +void test_c_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("c", "/*c*/"), + "c", "", "/*c*/", 0 + ); +} + +void test_c_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("c", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("c", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_c_tests() { + test_c_comments(); + test_c_empty_comments(); + test_c_block_comment(); + test_c_comment_entities(); +} diff --git a/test/unit/parsers/test_chaiscript.h b/test/unit/parsers/test_chaiscript.h new file mode 100644 index 0000000..6688011 --- /dev/null +++ b/test/unit/parsers/test_chaiscript.h @@ -0,0 +1,23 @@ + +void test_chaiscript_comments() { + test_parser_verify_parse( + test_parser_sourcefile("chaiscript", " //comment"), + "chaiscript", "", "//comment", 0 + ); +} + +void test_chaiscript_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("chaiscript", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("chaiscript", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_chaiscript_tests() { + test_chaiscript_comments(); + test_chaiscript_comment_entities(); +} diff --git a/test/unit/parsers/test_clearsilver.h b/test/unit/parsers/test_clearsilver.h new file mode 100644 index 0000000..63b1191 --- /dev/null +++ b/test/unit/parsers/test_clearsilver.h @@ -0,0 +1,19 @@ + +void test_clearsilver_comments() { + test_parser_verify_parse( + test_parser_sourcefile("clearsilver", " #comment"), + "clearsilver", "", "#comment", 0 + ); +} + +void test_clearsilver_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("clearsilver", " #comment"), + "comment", "#comment" + ); +} + +void all_clearsilver_tests() { + test_clearsilver_comments(); + test_clearsilver_comment_entities(); +} diff --git a/test/unit/parsers/test_clearsilvertemplate.h b/test/unit/parsers/test_clearsilvertemplate.h new file mode 100644 index 0000000..dcbf42d --- /dev/null +++ b/test/unit/parsers/test_clearsilvertemplate.h @@ -0,0 +1,24 @@ + +void test_clearsilver_template_comments() { + test_parser_verify_parse2( + test_parser_sourcefile("clearsilver_template", " "), + "html", "", "", 0, + "clearsilver", "", "#comment\n", 0 + ); +} + +void test_clearsilver_template_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("clearsilver_template", " "), + "comment", "" + ); + test_parser_verify_entity( + test_parser_sourcefile("clearsilver_template", " "), + "comment", "#comment" + ); +} + +void all_clearsilver_template_tests() { + test_clearsilver_template_comments(); + test_clearsilver_template_comment_entities(); +} diff --git a/test/unit/parsers/test_clojure.h b/test/unit/parsers/test_clojure.h new file mode 100644 index 0000000..bcb75f2 --- /dev/null +++ b/test/unit/parsers/test_clojure.h @@ -0,0 +1,19 @@ + +void test_clojure_comments() { + test_parser_verify_parse( + test_parser_sourcefile("clojure", " ;;; comment"), + "clojure", "", ";;; comment", 0 + ); +} + +void test_clojure_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("clojure", " ;comment"), + "comment", ";comment" + ); +} + +void all_clojure_tests() { + test_clojure_comments(); + test_clojure_comment_entities(); +} diff --git a/test/unit/parsers/test_cmake.h b/test/unit/parsers/test_cmake.h new file mode 100644 index 0000000..2fb8f1b --- /dev/null +++ b/test/unit/parsers/test_cmake.h @@ -0,0 +1,27 @@ + +void test_cmake_comments() { + test_parser_verify_parse( + test_parser_sourcefile("cmake", " #comment"), + "cmake", "", "#comment", 0 + ); +} + +void test_cmake_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("cmake", " #\n"), + "cmake", "", "#\n", 0 + ); +} + +void test_cmake_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("cmake", " #comment"), + "comment", "#comment" + ); +} + +void all_cmake_tests() { + test_cmake_comments(); + test_cmake_empty_comments(); + test_cmake_comment_entities(); +} diff --git a/test/unit/parsers/test_coq.h b/test/unit/parsers/test_coq.h new file mode 100644 index 0000000..d3f97c7 --- /dev/null +++ b/test/unit/parsers/test_coq.h @@ -0,0 +1,19 @@ + +void test_coq_comments() { + test_parser_verify_parse( + test_parser_sourcefile("coq", " (* comment *)"), + "coq", "", "(* comment *)", 0 + ); +} + +void test_coq_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("coq", " (*comment*)"), + "comment", "(*comment*)" + ); +} + +void all_coq_tests() { + test_coq_comments(); + test_coq_comment_entities(); +} diff --git a/test/unit/parsers/test_cs_aspx.h b/test/unit/parsers/test_cs_aspx.h new file mode 100644 index 0000000..4c2bbef --- /dev/null +++ b/test/unit/parsers/test_cs_aspx.h @@ -0,0 +1,12 @@ + +void test_cs_aspx_comments() { + test_parser_verify_parse2( + test_parser_sourcefile("cs_aspx", "<%\n //comment\n%>"), + "html", "<%\n%>", "", 0, + "csharp", "", "//comment\n", 0 + ); +} + +void all_cs_aspx_tests() { + test_cs_aspx_comments(); +} diff --git a/test/unit/parsers/test_csharp.h b/test/unit/parsers/test_csharp.h new file mode 100644 index 0000000..79ac52d --- /dev/null +++ b/test/unit/parsers/test_csharp.h @@ -0,0 +1,23 @@ + +void test_csharp_comments() { + test_parser_verify_parse( + test_parser_sourcefile("csharp", " //comment"), + "csharp", "", "//comment", 0 + ); +} + +void test_csharp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("csharp", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("csharp", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_csharp_tests() { + test_csharp_comments(); + test_csharp_comment_entities(); +} diff --git a/test/unit/parsers/test_css.h b/test/unit/parsers/test_css.h new file mode 100644 index 0000000..d6506d2 --- /dev/null +++ b/test/unit/parsers/test_css.h @@ -0,0 +1,19 @@ + +void test_css_comments() { + test_parser_verify_parse( + test_parser_sourcefile("css", " /*comment*/"), + "css", "", "/*comment*/", 0 + ); +} + +void test_css_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("css", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_css_tests() { + test_css_comments(); + test_css_comment_entities(); +} diff --git a/test/unit/parsers/test_d.h b/test/unit/parsers/test_d.h new file mode 100644 index 0000000..68f00d1 --- /dev/null +++ b/test/unit/parsers/test_d.h @@ -0,0 +1,63 @@ + +void test_dmd_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dmd", " //comment"), + "dmd", "", "//comment", 0 + ); +} + +void test_dmd_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dmd", " //\n"), + "dmd", "", "//\n", 0 + ); +} + +void test_dmd_strings() { + test_parser_verify_parse( + test_parser_sourcefile("dmd", "'/*' not a comment '*/'"), + "dmd", "'/*' not a comment '*/'", "", 0 + ); +} + +void test_dmd_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("dmd", " /*d*/"), + "dmd", "", "/*d*/", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("dmd", " /+d+/"), + "dmd", "", "/+d+/", 0 + ); +} + +void test_dmd_nested_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("dmd", "/+ /*d*/ not_code(); +/"), + "dmd", "", "/+ /*d*/ not_code(); +/", 0 + ); +} + +void test_dmd_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("dmd", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("dmd", " /*comment*/"), + "comment", "/*comment*/" + ); + test_parser_verify_entity( + test_parser_sourcefile("dmd", " /+comment+/"), + "comment", "/+comment+/" + ); +} + +void all_dmd_tests() { + test_dmd_comments(); + test_dmd_empty_comments(); + test_dmd_strings(); + test_dmd_block_comment(); + test_dmd_nested_block_comment(); + test_dmd_comment_entities(); +} diff --git a/test/unit/parsers/test_dcl.h b/test/unit/parsers/test_dcl.h new file mode 100644 index 0000000..64ccac1 --- /dev/null +++ b/test/unit/parsers/test_dcl.h @@ -0,0 +1,43 @@ + +void test_dcl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dcl", "$!comment"), + "dcl", "", "$!comment", 0 + ); +} + +void test_dcl_code() { + test_parser_verify_parse( + test_parser_sourcefile("dcl", "$code"), + "dcl", "$code", "", 0 + ); +} + +void test_dcl_blank() { + test_parser_verify_parse( + test_parser_sourcefile("dcl", "\n"), + "dcl", "", "", 1 + ); +} + +void test_dcl_input_line() { + test_parser_verify_parse( + test_parser_sourcefile("dcl", "input"), + "dcl", "input", "", 0 + ); +} + +void test_dcl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("dcl", " !comment"), + "comment", "!comment" + ); +} + +void all_dcl_tests() { + test_dcl_comments(); + test_dcl_code(); + test_dcl_blank(); + test_dcl_input_line(); + test_dcl_comment_entities(); +} diff --git a/test/unit/parsers/test_dylan.h b/test/unit/parsers/test_dylan.h new file mode 100644 index 0000000..8885d27 --- /dev/null +++ b/test/unit/parsers/test_dylan.h @@ -0,0 +1,23 @@ + +void test_dylan_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dylan", " //comment"), + "dylan", "", "//comment", 0 + ); +} + +void test_dylan_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("dylan", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("dylan", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_dylan_tests() { + test_dylan_comments(); + test_dylan_comment_entities(); +} diff --git a/test/unit/parsers/test_ebuild.h b/test/unit/parsers/test_ebuild.h new file mode 100644 index 0000000..4ae68a9 --- /dev/null +++ b/test/unit/parsers/test_ebuild.h @@ -0,0 +1,11 @@ + +void test_ebuild_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("ebuild", " #comment"), + "comment", "#comment" + ); +} + +void all_ebuild_tests() { + test_ebuild_comment_entities(); +} diff --git a/test/unit/parsers/test_eiffel.h b/test/unit/parsers/test_eiffel.h new file mode 100644 index 0000000..c533163 --- /dev/null +++ b/test/unit/parsers/test_eiffel.h @@ -0,0 +1,19 @@ + +void test_eiffel_comments() { + test_parser_verify_parse( + test_parser_sourcefile("eiffel", " --comment"), + "eiffel", "", "--comment", 0 + ); +} + +void test_eiffel_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("eiffel", " --comment"), + "comment", "--comment" + ); +} + +void all_eiffel_tests() { + test_eiffel_comments(); + test_eiffel_comment_entities(); +} diff --git a/test/unit/parsers/test_emacs_lisp.h b/test/unit/parsers/test_emacs_lisp.h new file mode 100644 index 0000000..c9a5beb --- /dev/null +++ b/test/unit/parsers/test_emacs_lisp.h @@ -0,0 +1,19 @@ + +void test_emacs_lisp_comments() { + test_parser_verify_parse( + test_parser_sourcefile("emacslisp", " ;;comment"), + "emacslisp", "", ";;comment", 0 + ); +} + +void test_emacs_lisp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("emacslisp", " ;comment"), + "comment", ";comment" + ); +} + +void all_emacs_lisp_tests() { + test_emacs_lisp_comments(); + test_emacs_lisp_comment_entities(); +} diff --git a/test/unit/parsers/test_erlang.h b/test/unit/parsers/test_erlang.h new file mode 100644 index 0000000..c3bd0fa --- /dev/null +++ b/test/unit/parsers/test_erlang.h @@ -0,0 +1,19 @@ + +void test_erlang_comments() { + test_parser_verify_parse( + test_parser_sourcefile("erlang", " %%comment"), + "erlang", "", "%%comment", 0 + ); +} + +void test_erlang_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("erlang", " %comment"), + "comment", "%comment" + ); +} + +void all_erlang_tests() { + test_erlang_comments(); + test_erlang_comment_entities(); +} diff --git a/test/unit/parsers/test_exheres.h b/test/unit/parsers/test_exheres.h new file mode 100644 index 0000000..566ca38 --- /dev/null +++ b/test/unit/parsers/test_exheres.h @@ -0,0 +1,11 @@ + +void test_exheres_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("exheres", " #comment"), + "comment", "#comment" + ); +} + +void all_exheres_tests() { + test_exheres_comment_entities(); +} diff --git a/test/unit/parsers/test_factor.h b/test/unit/parsers/test_factor.h new file mode 100644 index 0000000..fbf2c4e --- /dev/null +++ b/test/unit/parsers/test_factor.h @@ -0,0 +1,19 @@ + +void test_factor_comments() { + test_parser_verify_parse( + test_parser_sourcefile("factor", " ! comment"), + "factor", "", "! comment", 0 + ); +} + +void test_factor_strings() { + test_parser_verify_parse( + test_parser_sourcefile("factor", "\"abc!not a 'comment\""), + "factor", "\"abc!not a 'comment\"", "", 0 + ); +} + +void all_factor_tests() { + test_factor_comments(); + test_factor_strings(); +} diff --git a/test/unit/parsers/test_forth.h b/test/unit/parsers/test_forth.h new file mode 100644 index 0000000..9f93497 --- /dev/null +++ b/test/unit/parsers/test_forth.h @@ -0,0 +1,15 @@ + +void test_forth_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("forth", " \\comment"), + "comment", "\\comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("forth", " (comment)"), + "comment", "(comment)" + ); +} + +void all_forth_tests() { + test_forth_comment_entities(); +} diff --git a/test/unit/parsers/test_fortran.h b/test/unit/parsers/test_fortran.h new file mode 100644 index 0000000..c6d772c --- /dev/null +++ b/test/unit/parsers/test_fortran.h @@ -0,0 +1,15 @@ + +void test_fortran_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("fortranfree", " !comment"), + "comment", "!comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("fortranfixed", "C comment"), + "comment", "C comment" + ); +} + +void all_fortran_tests() { + test_fortran_comment_entities(); +} diff --git a/test/unit/parsers/test_fsharp.h b/test/unit/parsers/test_fsharp.h new file mode 100644 index 0000000..3289e92 --- /dev/null +++ b/test/unit/parsers/test_fsharp.h @@ -0,0 +1,23 @@ + +void test_fsharp_comments() { + test_parser_verify_parse( + test_parser_sourcefile("fsharp", " //comment"), + "fsharp", "", "//comment", 0 + ); +} + +void test_fsharp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("fsharp", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("fsharp", " (*comment*)"), + "comment", "(*comment*)" + ); +} + +void all_fsharp_tests() { + test_fsharp_comments(); + test_fsharp_comment_entities(); +} diff --git a/test/unit/parsers/test_glsl.h b/test/unit/parsers/test_glsl.h new file mode 100644 index 0000000..b545d25 --- /dev/null +++ b/test/unit/parsers/test_glsl.h @@ -0,0 +1,39 @@ + +void test_glsl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("glsl", " //comment"), + "glsl", "", "//comment", 0 + ); +} + +void test_glsl_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("glsl", " //\n"), + "glsl", "", "//\n", 0 + ); +} + +void test_glsl_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("glsl", "/*glsl*/"), + "glsl", "", "/*glsl*/", 0 + ); +} + +void test_glsl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("glsl", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("glsl", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_glsl_tests() { + test_glsl_comments(); + test_glsl_empty_comments(); + test_glsl_block_comment(); + test_glsl_comment_entities(); +} diff --git a/test/unit/parsers/test_golang.h b/test/unit/parsers/test_golang.h new file mode 100644 index 0000000..7463d4b --- /dev/null +++ b/test/unit/parsers/test_golang.h @@ -0,0 +1,39 @@ + +void test_golang_comments() { + test_parser_verify_parse( + test_parser_sourcefile("go", " //comment"), + "go", "", "//comment", 0 + ); +} + +void test_golang_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("go", " //\n"), + "go", "", "//\n", 0 + ); +} + +void test_golang_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("go", "/*c*/"), + "go", "", "/*c*/", 0 + ); +} + +void test_golang_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("go", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("go", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_golang_tests() { + test_golang_comments(); + test_golang_empty_comments(); + test_golang_block_comment(); + test_golang_comment_entities(); +} diff --git a/test/unit/parsers/test_groovy.h b/test/unit/parsers/test_groovy.h new file mode 100644 index 0000000..f8e1eb9 --- /dev/null +++ b/test/unit/parsers/test_groovy.h @@ -0,0 +1,23 @@ + +void test_groovy_comments() { + test_parser_verify_parse( + test_parser_sourcefile("groovy", " //comment"), + "groovy", "", "//comment", 0 + ); +} + +void test_groovy_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("groovy", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("groovy", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_groovy_tests() { + test_groovy_comments(); + test_groovy_comment_entities(); +} diff --git a/test/unit/parsers/test_haml.h b/test/unit/parsers/test_haml.h new file mode 100644 index 0000000..19fb8d0 --- /dev/null +++ b/test/unit/parsers/test_haml.h @@ -0,0 +1,35 @@ + +void test_haml_comment() { + test_parser_verify_parse( + test_parser_sourcefile("haml", "/ comment"), + "haml", "", "/ comment", 0 + ); +} + +void test_haml_element() { + test_parser_verify_parse( + test_parser_sourcefile("haml", " %code"), + "haml", "%code", "", 0 + ); +} + +void test_haml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("haml", " %element"), + "element", "%element" + ); + test_parser_verify_entity( + test_parser_sourcefile("haml", " .class"), + "element_class", ".class" + ); + test_parser_verify_entity( + test_parser_sourcefile("haml", " #id"), + "element_id", "#id" + ); +} + +void all_haml_tests() { + test_haml_comment(); + test_haml_element(); + test_haml_comment_entities(); +} diff --git a/test/unit/parsers/test_haskell.h b/test/unit/parsers/test_haskell.h new file mode 100644 index 0000000..1b26362 --- /dev/null +++ b/test/unit/parsers/test_haskell.h @@ -0,0 +1,23 @@ + +void test_haskell_comments() { + test_parser_verify_parse( + test_parser_sourcefile("haskell", " --comment"), + "haskell", "", "--comment", 0 + ); +} + +void test_haskell_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("haskell", " --comment"), + "comment", "--comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("haskell", " {-comment-}"), + "comment", "{-comment-}" + ); +} + +void all_haskell_tests() { + test_haskell_comments(); + test_haskell_comment_entities(); +} diff --git a/test/unit/parsers/test_haxe.h b/test/unit/parsers/test_haxe.h new file mode 100644 index 0000000..777e8bb --- /dev/null +++ b/test/unit/parsers/test_haxe.h @@ -0,0 +1,23 @@ + +void test_haxe_comments() { + test_parser_verify_parse( + test_parser_sourcefile("haxe", " //comment"), + "haxe", "", "//comment", 0 + ); +} + +void test_haxe_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("haxe", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("haxe", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_haxe_tests() { + test_haxe_comments(); + test_haxe_comment_entities(); +} diff --git a/test/unit/parsers/test_html.h b/test/unit/parsers/test_html.h new file mode 100644 index 0000000..0fbd1e8 --- /dev/null +++ b/test/unit/parsers/test_html.h @@ -0,0 +1,23 @@ + +void test_html_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("html", " "), + "comment", "" + ); + test_parser_verify_entity( + test_parser_sourcefile("html", ""), + "comment", "/*comment*/" + ); + test_parser_verify_entity( + test_parser_sourcefile("html", ""), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("html", ""), + "comment", "/*comment*/" + ); +} + +void all_html_tests() { + test_html_comment_entities(); +} diff --git a/test/unit/parsers/test_idl_pvwave.h b/test/unit/parsers/test_idl_pvwave.h new file mode 100644 index 0000000..0eeb346 --- /dev/null +++ b/test/unit/parsers/test_idl_pvwave.h @@ -0,0 +1,28 @@ +void test_idl_pvwave_comments() { + test_parser_verify_parse( + test_parser_sourcefile("idl_pvwave", " ;comment"), + "idl_pvwave", "", ";comment", 0 + ); +} + +void test_idl_pvwave_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("idl_pvwave", " ;comment"), + "comment", ";comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("idl_pvwave", " ;comment"), + "comment", ";comment" + ); +} + +void test_idl_pvwave_is_language() { + const char *language = "idl_pvwave"; + assert(ohcount_hash_language_from_name(language, strlen(language)) != NULL); +} + +void all_idl_pvwave_tests() { + test_idl_pvwave_is_language(); + test_idl_pvwave_comments(); + test_idl_pvwave_comment_entities(); +} diff --git a/test/unit/parsers/test_jam.h b/test/unit/parsers/test_jam.h new file mode 100644 index 0000000..373a6be --- /dev/null +++ b/test/unit/parsers/test_jam.h @@ -0,0 +1,19 @@ + +void test_jam_comments() { + test_parser_verify_parse( + test_parser_sourcefile("jam", " #comment"), + "jam", "", "#comment", 0 + ); +} + +void test_jam_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("jam", " #comment"), + "comment", "#comment" + ); +} + +void all_jam_tests() { + test_jam_comments(); + test_jam_comment_entities(); +} diff --git a/test/unit/parsers/test_java.h b/test/unit/parsers/test_java.h new file mode 100644 index 0000000..e46afd8 --- /dev/null +++ b/test/unit/parsers/test_java.h @@ -0,0 +1,23 @@ + +void test_java_comments() { + test_parser_verify_parse( + test_parser_sourcefile("java", " //comment"), + "java", "", "//comment", 0 + ); +} + +void test_java_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("java", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("java", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_java_tests() { + test_java_comments(); + test_java_comment_entities(); +} diff --git a/test/unit/parsers/test_javascript.h b/test/unit/parsers/test_javascript.h new file mode 100644 index 0000000..766bb09 --- /dev/null +++ b/test/unit/parsers/test_javascript.h @@ -0,0 +1,23 @@ + +void test_javascript_comments() { + test_parser_verify_parse( + test_parser_sourcefile("javascript", " //comment"), + "javascript", "", "//comment", 0 + ); +} + +void test_javascript_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("javascript", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("javascript", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_javascript_tests() { + test_javascript_comments(); + test_javascript_comment_entities(); +} diff --git a/test/unit/parsers/test_jsp.h b/test/unit/parsers/test_jsp.h new file mode 100644 index 0000000..0aada71 --- /dev/null +++ b/test/unit/parsers/test_jsp.h @@ -0,0 +1,31 @@ + +void test_jsp_comment() { + test_parser_verify_parse2( + test_parser_sourcefile("jsp", " <% //comment\n%>"), + "java", "", "<% //comment\n", 0, + "html", "%>", "", 0 + ); +} + +void test_jsp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("jsp", " "), + "comment", "" + ); + test_parser_verify_entity( + test_parser_sourcefile("jsp", ""), + "comment", "/*comment*/" + ); + test_parser_verify_entity( + test_parser_sourcefile("jsp", "<%\n//comment\n%>"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("jsp", "<%\n/*comment*/\n%>"), + "comment", "/*comment*/" + ); +} + +void all_jsp_tests() { + test_jsp_comment_entities(); +} diff --git a/test/unit/parsers/test_lisp.h b/test/unit/parsers/test_lisp.h new file mode 100644 index 0000000..abbc21c --- /dev/null +++ b/test/unit/parsers/test_lisp.h @@ -0,0 +1,51 @@ + +void test_lisp_comment() { + test_parser_verify_parse( + test_parser_sourcefile("lisp", " ;;; comment"), + "lisp", "", ";;; comment", 0 + ); +} + +void test_lisp_doc_string() { + test_parser_verify_parse( + test_parser_sourcefile("lisp", " \"\"\" comment \"\"\""), + "lisp", "", "\"\"\" comment \"\"\"", 0 + ); +} + +void test_lisp_doc_string_blank() { + test_parser_verify_parse( + test_parser_sourcefile("lisp", " \"\"\"\"\"\""), + "lisp", "", "\"\"\"\"\"\"", 0 + ); +} + +void test_lisp_empty_string() { + test_parser_verify_parse( + test_parser_sourcefile("lisp", "\"\""), + "lisp", "\"\"", "", 0 + ); +} + +void test_lisp_char_string() { + test_parser_verify_parse( + test_parser_sourcefile("lisp", " \"a\""), + "lisp", "\"a\"", "", 0 + ); +} + +void test_lisp_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("lisp", " ;comment"), + "comment", ";comment" + ); +} + +void all_lisp_tests() { + test_lisp_comment(); + test_lisp_doc_string(); + test_lisp_doc_string_blank(); + test_lisp_empty_string(); + test_lisp_char_string(); + test_lisp_comment_entities(); +} diff --git a/test/unit/parsers/test_logtalk.h b/test/unit/parsers/test_logtalk.h new file mode 100644 index 0000000..8b83ffb --- /dev/null +++ b/test/unit/parsers/test_logtalk.h @@ -0,0 +1,27 @@ + +void test_logtalk_comments() { + test_parser_verify_parse( + test_parser_sourcefile("logtalk", " %comment"), + "logtalk", "", "%comment", 0 + ); +} + +void test_logtalk_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("logtalk", " %\n"), + "logtalk", "", "%\n", 0 + ); +} + +void test_logtalk_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("logtalk", " /*d*/"), + "logtalk", "", "/*d*/", 0 + ); +} + +void all_logtalk_tests() { + test_logtalk_comments(); + test_logtalk_empty_comments(); + test_logtalk_block_comment(); +} diff --git a/test/unit/parsers/test_lua.h b/test/unit/parsers/test_lua.h new file mode 100644 index 0000000..0f3bf97 --- /dev/null +++ b/test/unit/parsers/test_lua.h @@ -0,0 +1,23 @@ + +void test_lua_comments() { + test_parser_verify_parse( + test_parser_sourcefile("lua", " -- comment"), + "lua", "", "-- comment", 0 + ); +} + +void test_lua_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("lua", " --comment"), + "comment", "--comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("lua", " --[[comment\ncomment]]"), + "comment", "--[[comment\ncomment]]" + ); +} + +void all_lua_tests() { + test_lua_comments(); + test_lua_comment_entities(); +} diff --git a/test/unit/parsers/test_make.h b/test/unit/parsers/test_make.h new file mode 100644 index 0000000..b4b4e2a --- /dev/null +++ b/test/unit/parsers/test_make.h @@ -0,0 +1,11 @@ + +void test_make_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("make", " #comment"), + "comment", "#comment" + ); +} + +void all_make_tests() { + test_make_comment_entities(); +} diff --git a/test/unit/parsers/test_mathematica.h b/test/unit/parsers/test_mathematica.h new file mode 100644 index 0000000..855bd36 --- /dev/null +++ b/test/unit/parsers/test_mathematica.h @@ -0,0 +1,11 @@ + +void test_mathematica_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("mathematica", " (*comment*)"), + "comment", "(*comment*)" + ); +} + +void all_mathematica_tests() { + test_mathematica_comment_entities(); +} diff --git a/test/unit/parsers/test_matlab.h b/test/unit/parsers/test_matlab.h new file mode 100644 index 0000000..47c8cbd --- /dev/null +++ b/test/unit/parsers/test_matlab.h @@ -0,0 +1,43 @@ + +void test_matlab_line_comment_1() { + test_parser_verify_parse( + test_parser_sourcefile("matlab", " %comment"), + "matlab", "", "%comment", 0 + ); +} + +void test_matlab_ancient_syntax_comment() { + test_parser_verify_parse( + test_parser_sourcefile("matlab", " ... comment"), + "matlab", "", "... comment", 0 + ); +} + +void test_matlab_false_line_comment() { + test_parser_verify_parse( + test_parser_sourcefile("matlab", " %{block%} code"), + "matlab", "%{block%} code", "", 0 + ); +} + +void test_matlab_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("matlab", " %comment"), + "comment", "%comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("matlab", " ... comment"), + "comment", "... comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("matlab", " %{comment%}"), + "comment", "%{comment%}" + ); +} + +void all_matlab_tests() { + test_matlab_line_comment_1(); + test_matlab_ancient_syntax_comment(); + test_matlab_false_line_comment(); + test_matlab_comment_entities(); +} diff --git a/test/unit/parsers/test_metafont.h b/test/unit/parsers/test_metafont.h new file mode 100644 index 0000000..d9f68a4 --- /dev/null +++ b/test/unit/parsers/test_metafont.h @@ -0,0 +1,19 @@ + +void test_metafont_comments() { + test_parser_verify_parse( + test_parser_sourcefile("metafont", " % comment"), + "metafont", "", "% comment", 0 + ); +} + +void test_metafont_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("metafont", " %comment"), + "comment", "%comment" + ); +} + +void all_metafont_tests() { + test_metafont_comments(); + test_metafont_comment_entities(); +} diff --git a/test/unit/parsers/test_metapost.h b/test/unit/parsers/test_metapost.h new file mode 100644 index 0000000..9982b06 --- /dev/null +++ b/test/unit/parsers/test_metapost.h @@ -0,0 +1,23 @@ + +void test_metapost_comments() { + test_parser_verify_parse( + test_parser_sourcefile("metapost", " % comment"), + "metapost", "", "% comment", 0 + ); +} + +void test_metapost_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("metapost", " %comment"), + "comment", "%comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("metapost", "verbatim\n%comment\netex"), + "comment", "%comment" + ); +} + +void all_metapost_tests() { + test_metapost_comments(); + test_metapost_comment_entities(); +} diff --git a/test/unit/parsers/test_mxml.h b/test/unit/parsers/test_mxml.h new file mode 100644 index 0000000..f32bdda --- /dev/null +++ b/test/unit/parsers/test_mxml.h @@ -0,0 +1,23 @@ + +void test_mxml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("mxml", " "), + "comment", "" + ); + test_parser_verify_entity( + test_parser_sourcefile("mxml", "\n/*comment*/\n"), + "comment", "/*comment*/" + ); + test_parser_verify_entity( + test_parser_sourcefile("mxml", "\n//comment\n"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("mxml", "\n/*comment*/\n"), + "comment", "/*comment*/" + ); +} + +void all_mxml_tests() { + test_mxml_comment_entities(); +} diff --git a/test/unit/parsers/test_nix.h b/test/unit/parsers/test_nix.h new file mode 100644 index 0000000..26aefb2 --- /dev/null +++ b/test/unit/parsers/test_nix.h @@ -0,0 +1,11 @@ + +void test_nix_line_comments() { + test_parser_verify_parse( + test_parser_sourcefile("nix", "# comment"), + "nix", "", "# comment", 0 + ); +} + +void all_nix_tests() { + test_nix_line_comments(); +} diff --git a/test/unit/parsers/test_nsis.h b/test/unit/parsers/test_nsis.h new file mode 100644 index 0000000..027ee5f --- /dev/null +++ b/test/unit/parsers/test_nsis.h @@ -0,0 +1,51 @@ + +void test_nsis_comments() { + test_parser_verify_parse( + test_parser_sourcefile("nsis", " ;comment"), + "nsis", "", ";comment", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("nsis", " #comment"), + "nsis", "", "#comment", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("nsis", " /*comment*/"), + "nsis", "", "/*comment*/", 0 + ); +} + +void test_nsis_strings() { + test_parser_verify_parse( + test_parser_sourcefile("nsis", "\"abc;not a 'comment\""), + "nsis", "\"abc;not a 'comment\"", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("nsis", "'abc;not a \"comment'"), + "nsis", "'abc;not a \"comment'", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("nsis", "`abc;not a 'comment`"), + "nsis", "`abc;not a 'comment`", "", 0 + ); +} + +void test_nsis_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("nsis", " ;comment"), + "comment", ";comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("nsis", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("nsis", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_nsis_tests() { + test_nsis_comments(); + test_nsis_strings(); + test_nsis_comment_entities(); +} diff --git a/test/unit/parsers/test_objective_j.h b/test/unit/parsers/test_objective_j.h new file mode 100644 index 0000000..818e422 --- /dev/null +++ b/test/unit/parsers/test_objective_j.h @@ -0,0 +1,23 @@ + +void test_objective_j_comments() { + test_parser_verify_parse( + test_parser_sourcefile("objective_j", " //comment"), + "objective_j", "", "//comment", 0 + ); +} + +void test_objective_j_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("objective_j", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("objective_j", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_objective_j_tests() { + test_objective_j_comments(); + test_objective_j_comment_entities(); +} diff --git a/test/unit/parsers/test_ocaml.h b/test/unit/parsers/test_ocaml.h new file mode 100644 index 0000000..1293e05 --- /dev/null +++ b/test/unit/parsers/test_ocaml.h @@ -0,0 +1,19 @@ + +void test_ocaml_comments() { + test_parser_verify_parse( + test_parser_sourcefile("ocaml", " (* comment *)"), + "ocaml", "", "(* comment *)", 0 + ); +} + +void test_ocaml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("ocaml", " (*comment*)"), + "comment", "(*comment*)" + ); +} + +void all_ocaml_tests() { + test_ocaml_comments(); + test_ocaml_comment_entities(); +} diff --git a/test/unit/parsers/test_octave.h b/test/unit/parsers/test_octave.h new file mode 100644 index 0000000..3ca84a6 --- /dev/null +++ b/test/unit/parsers/test_octave.h @@ -0,0 +1,39 @@ + +void test_octave_line_comment_1() { + test_parser_verify_parse( + test_parser_sourcefile("octave", " %comment"), + "octave", "", "%comment", 0 + ); +} + +void test_octave_syntax_comment() { + test_parser_verify_parse( + test_parser_sourcefile("octave", " # comment"), + "octave", "", "# comment", 0 + ); +} + +void test_octave_false_line_comment() { + test_parser_verify_parse( + test_parser_sourcefile("octave", " %{block%} code"), + "octave", "%{block%} code", "", 0 + ); +} + +void test_octave_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("octave", " %comment"), + "comment", "%comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("octave", " # comment"), + "comment", "# comment" + ); +} + +void all_octave_tests() { + test_octave_line_comment_1(); + test_octave_syntax_comment(); + test_octave_false_line_comment(); + test_octave_comment_entities(); +} diff --git a/test/unit/parsers/test_pascal.h b/test/unit/parsers/test_pascal.h new file mode 100644 index 0000000..65fea37 --- /dev/null +++ b/test/unit/parsers/test_pascal.h @@ -0,0 +1,27 @@ + +void test_pascal_comments() { + test_parser_verify_parse( + test_parser_sourcefile("pascal", " //comment"), + "pascal", "", "//comment", 0 + ); +} + +void test_pascal_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("pascal", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("pascal", " (*comment*)"), + "comment", "(*comment*)" + ); + test_parser_verify_entity( + test_parser_sourcefile("pascal", " {comment}"), + "comment", "{comment}" + ); +} + +void all_pascal_tests() { + test_pascal_comments(); + test_pascal_comment_entities(); +} diff --git a/test/unit/parsers/test_perl.h b/test/unit/parsers/test_perl.h new file mode 100644 index 0000000..8dd5ba2 --- /dev/null +++ b/test/unit/parsers/test_perl.h @@ -0,0 +1,23 @@ + +void test_perl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("perl", " #comment"), + "perl", "", "#comment", 0 + ); +} + +void test_perl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("perl", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("perl", "=head1\ncomment\n=cut"), + "comment", "=head1\ncomment\n=cut" + ); +} + +void all_perl_tests() { + test_perl_comments(); + test_perl_comment_entities(); +} diff --git a/test/unit/parsers/test_pike.h b/test/unit/parsers/test_pike.h new file mode 100644 index 0000000..62e3297 --- /dev/null +++ b/test/unit/parsers/test_pike.h @@ -0,0 +1,23 @@ + +void test_pike_comments() { + test_parser_verify_parse( + test_parser_sourcefile("pike", " //comment"), + "pike", "", "//comment", 0 + ); +} + +void test_pike_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("pike", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("pike", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_pike_tests() { + test_pike_comments(); + test_pike_comment_entities(); +} diff --git a/test/unit/parsers/test_puppet.h b/test/unit/parsers/test_puppet.h new file mode 100644 index 0000000..8d55b09 --- /dev/null +++ b/test/unit/parsers/test_puppet.h @@ -0,0 +1,23 @@ + +void test_puppet_comments() { + test_parser_verify_parse( + test_parser_sourcefile("puppet", " #comment"), + "puppet", "", "#comment", 0 + ); +} + +void test_puppet_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("puppet", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("puppet", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_puppet_tests() { + test_puppet_comments(); + test_puppet_comment_entities(); +} diff --git a/test/unit/parsers/test_python.h b/test/unit/parsers/test_python.h new file mode 100644 index 0000000..28ba7cd --- /dev/null +++ b/test/unit/parsers/test_python.h @@ -0,0 +1,39 @@ + +void test_python_comment() { + test_parser_verify_parse( + test_parser_sourcefile("python", " #comment"), + "python", "", "#comment", 0 + ); +} + +void test_python_doc_string() { + test_parser_verify_parse( + test_parser_sourcefile("python", " '''\n doc comment\n '''"), + "python", "", "'''\ndoc comment\n'''", 0 + ); +} + +void test_python_strings() { + test_parser_verify_parse( + test_parser_sourcefile("python", "\"abc#not a 'comment\""), + "python", "\"abc#not a 'comment\"", "", 0 + ); +} + +void test_python_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("python", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("python", " \"\"\"comment\"\"\""), + "comment", "\"\"\"comment\"\"\"" + ); +} + +void all_python_tests() { + test_python_comment(); + test_python_doc_string(); + test_python_strings(); + test_python_comment_entities(); +} diff --git a/test/unit/parsers/test_qml.h b/test/unit/parsers/test_qml.h new file mode 100644 index 0000000..d4ba843 --- /dev/null +++ b/test/unit/parsers/test_qml.h @@ -0,0 +1,23 @@ + +void test_qml_comments() { + test_parser_verify_parse( + test_parser_sourcefile("qml", " //comment"), + "qml", "", "//comment", 0 + ); +} + +void test_qml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("qml", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("qml", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_qml_tests() { + test_qml_comments(); + test_qml_comment_entities(); +} diff --git a/test/unit/parsers/test_r.h b/test/unit/parsers/test_r.h new file mode 100644 index 0000000..350b310 --- /dev/null +++ b/test/unit/parsers/test_r.h @@ -0,0 +1,19 @@ + +void test_r_comments() { + test_parser_verify_parse( + test_parser_sourcefile("r", " #comment"), + "r", "", "#comment", 0 + ); +} + +void test_r_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("r", " #comment"), + "comment", "#comment" + ); +} + +void all_r_tests() { + test_r_comments(); + test_r_comment_entities(); +} diff --git a/test/unit/parsers/test_racket.h b/test/unit/parsers/test_racket.h new file mode 100644 index 0000000..9267a8f --- /dev/null +++ b/test/unit/parsers/test_racket.h @@ -0,0 +1,54 @@ +/* renamed from lisp unit tests... + * lots more possible here. + */ + +void test_racket_comment() { + test_parser_verify_parse( + test_parser_sourcefile("racket", " ;;; comment"), + "racket", "", ";;; comment", 0 + ); +} + +void test_racket_doc_string() { + test_parser_verify_parse( + test_parser_sourcefile("racket", " \"\"\" comment \"\"\""), + "racket", "", "\"\"\" comment \"\"\"", 0 + ); +} + +void test_racket_doc_string_blank() { + test_parser_verify_parse( + test_parser_sourcefile("racket", " \"\"\"\"\"\""), + "racket", "", "\"\"\"\"\"\"", 0 + ); +} + +void test_racket_empty_string() { + test_parser_verify_parse( + test_parser_sourcefile("racket", "\"\""), + "racket", "\"\"", "", 0 + ); +} + +void test_racket_char_string() { + test_parser_verify_parse( + test_parser_sourcefile("racket", " \"a\""), + "racket", "\"a\"", "", 0 + ); +} + +void test_racket_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("racket", " ;comment"), + "comment", ";comment" + ); +} + +void all_racket_tests() { + test_racket_comment(); + test_racket_doc_string(); + test_racket_doc_string_blank(); + test_racket_empty_string(); + test_racket_char_string(); + test_racket_comment_entities(); +} diff --git a/test/unit/parsers/test_rebol.h b/test/unit/parsers/test_rebol.h new file mode 100644 index 0000000..95bace9 --- /dev/null +++ b/test/unit/parsers/test_rebol.h @@ -0,0 +1,43 @@ + +void test_rebol_comments() { + test_parser_verify_parse( + test_parser_sourcefile("rebol", "REBOL []\n;comment"), + "rebol", "REBOL []\n", ";comment", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("rebol", "{}"), + "rebol", "{}", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("rebol", "{{}}"), + "rebol", "{{}}", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("rebol", "{{\n}}"), + "rebol", "{{\n}}", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("rebol", "{\n;inside string\n}"), + "rebol", "{\n;inside string\n}", "", 0 + ); + test_parser_verify_parse( + test_parser_sourcefile("rebol", "{}\n;comment"), + "rebol", "{}\n", ";comment", 0 + ); +} + +void test_rebol_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("rebol", " ;comment"), + "comment", ";comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("rebol", " \";no comment\""), + "string", "\";no comment\"" + ); +} + +void all_rebol_tests() { + test_rebol_comments(); + test_rebol_comment_entities(); +} diff --git a/test/unit/parsers/test_rexx.h b/test/unit/parsers/test_rexx.h new file mode 100644 index 0000000..a458f3c --- /dev/null +++ b/test/unit/parsers/test_rexx.h @@ -0,0 +1,19 @@ + +void test_rexx_comment() { + test_parser_verify_parse( + test_parser_sourcefile("rexx", " /*comment*/"), + "rexx", "", "/*comment*/", 0 + ); +} + +void test_rexx_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("rexx", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_rexx_tests() { + test_rexx_comment(); + test_rexx_comment_entities(); +} diff --git a/test/unit/parsers/test_rhtml.h b/test/unit/parsers/test_rhtml.h new file mode 100644 index 0000000..eb119f6 --- /dev/null +++ b/test/unit/parsers/test_rhtml.h @@ -0,0 +1,12 @@ + +void test_rhtml_comment() { + test_parser_verify_parse2( + test_parser_sourcefile("rhtml", "<%\n #comment\n%>"), + "html", "<%\n%>", "", 0, + "ruby", "", "#comment\n", 0 + ); +} + +void all_rhtml_tests() { + test_rhtml_comment(); +} diff --git a/test/unit/parsers/test_ruby.h b/test/unit/parsers/test_ruby.h new file mode 100644 index 0000000..e29843b --- /dev/null +++ b/test/unit/parsers/test_ruby.h @@ -0,0 +1,23 @@ + +void test_ruby_comments() { + test_parser_verify_parse( + test_parser_sourcefile("ruby", " #comment"), + "ruby", "", "#comment", 0 + ); +} + +void test_ruby_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("ruby", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("ruby", "=begin\ncomment\n=end"), + "comment", "=begin\ncomment\n=end" + ); +} + +void all_ruby_tests() { + test_ruby_comments(); + test_ruby_comment_entities(); +} diff --git a/test/unit/parsers/test_scala.h b/test/unit/parsers/test_scala.h new file mode 100644 index 0000000..5a124ee --- /dev/null +++ b/test/unit/parsers/test_scala.h @@ -0,0 +1,15 @@ + +void test_scala_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("scala", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("scala", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_scala_tests() { + test_scala_comment_entities(); +} diff --git a/test/unit/parsers/test_scheme.h b/test/unit/parsers/test_scheme.h new file mode 100644 index 0000000..9ba6062 --- /dev/null +++ b/test/unit/parsers/test_scheme.h @@ -0,0 +1,19 @@ + +void test_scheme_comments() { + test_parser_verify_parse( + test_parser_sourcefile("scheme", " ;;; comment"), + "scheme", "", ";;; comment", 0 + ); +} + +void test_scheme_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("scheme", " ;comment"), + "comment", ";comment" + ); +} + +void all_scheme_tests() { + test_scheme_comments(); + test_scheme_comment_entities(); +} diff --git a/test/unit/parsers/test_scilab.h b/test/unit/parsers/test_scilab.h new file mode 100644 index 0000000..f6bd60b --- /dev/null +++ b/test/unit/parsers/test_scilab.h @@ -0,0 +1,19 @@ + +void test_scilab_comments() { + test_parser_verify_parse( + test_parser_sourcefile("scilab", " //comment"), + "scilab", "", "//comment", 0 + ); +} + +void test_scilab_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("scilab", " //comment"), + "comment", "//comment" + ); +} + +void all_scilab_tests() { + test_scilab_comments(); + test_scilab_comment_entities(); +} diff --git a/test/unit/parsers/test_shell.h b/test/unit/parsers/test_shell.h new file mode 100644 index 0000000..2797532 --- /dev/null +++ b/test/unit/parsers/test_shell.h @@ -0,0 +1,19 @@ + +void test_shell_comments() { + test_parser_verify_parse( + test_parser_sourcefile("shell", " #comment"), + "shell", "", "#comment", 0 + ); +} + +void test_shell_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("shell", " #comment"), + "comment", "#comment" + ); +} + +void all_shell_tests() { + test_shell_comments(); + test_shell_comment_entities(); +} diff --git a/test/unit/parsers/test_smalltalk.h b/test/unit/parsers/test_smalltalk.h new file mode 100644 index 0000000..cbdc285 --- /dev/null +++ b/test/unit/parsers/test_smalltalk.h @@ -0,0 +1,19 @@ + +void test_smalltalk_comments() { + test_parser_verify_parse( + test_parser_sourcefile("smalltalk", " \"comment\\\""), + "smalltalk", "", "\"comment\\\"", 0 + ); +} + +void test_smalltalk_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("smalltalk", " \"comment\""), + "comment", "\"comment\"" + ); +} + +void all_smalltalk_tests() { + test_smalltalk_comments(); + test_smalltalk_comment_entities(); +} diff --git a/test/unit/parsers/test_sql.h b/test/unit/parsers/test_sql.h new file mode 100644 index 0000000..a6e85ed --- /dev/null +++ b/test/unit/parsers/test_sql.h @@ -0,0 +1,51 @@ + +void test_sql_comments() { + test_parser_verify_parse( + test_parser_sourcefile("sql", " --comment"), + "sql", "", "--comment", 0 + ); +} + +void test_sql_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("sql", " --\n"), + "sql", "", "--\n", 0 + ); +} + +void test_sql_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("sql", " {sql}"), + "sql", "", "{sql}", 0 + ); +} + +void test_sql_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("sql", " --comment"), + "comment", "--comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("sql", " #comment"), + "comment", "#comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("sql", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("sql", " /*comment*/"), + "comment", "/*comment*/" + ); + test_parser_verify_entity( + test_parser_sourcefile("sql", " {comment}"), + "comment", "{comment}" + ); +} + +void all_sql_tests() { + test_sql_comments(); + test_sql_empty_comments(); + test_sql_block_comment(); + test_sql_comment_entities(); +} diff --git a/test/unit/parsers/test_stratego.h b/test/unit/parsers/test_stratego.h new file mode 100644 index 0000000..93aad0e --- /dev/null +++ b/test/unit/parsers/test_stratego.h @@ -0,0 +1,30 @@ + +void test_stratego_comments() { + test_parser_verify_parse( + test_parser_sourcefile("stratego", " // comment"), + "stratego", "", "// comment", 0 + ); +} + +void test_stratego_char_string_entities() { + test_parser_verify_entity( + test_parser_sourcefile("stratego", " 'c'"), + "string", "'c'" + ); + // single quote can be used in identifiers + // weak case + test_parser_verify_entity( + test_parser_sourcefile("stratego", " c'"), + "string", "" + ); + // strong case + test_parser_verify_entity( + test_parser_sourcefile("stratego", " c' = e'"), + "string", "" + ); +} + +void all_stratego_tests() { + test_stratego_comments(); + test_stratego_char_string_entities(); +} diff --git a/test/unit/parsers/test_tcl.h b/test/unit/parsers/test_tcl.h new file mode 100644 index 0000000..2fa10d8 --- /dev/null +++ b/test/unit/parsers/test_tcl.h @@ -0,0 +1,19 @@ + +void test_tcl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("tcl", " #comment"), + "tcl", "", "#comment", 0 + ); +} + +void test_tcl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("tcl", " #comment"), + "comment", "#comment" + ); +} + +void all_tcl_tests() { + test_tcl_comments(); + test_tcl_comment_entities(); +} diff --git a/test/unit/parsers/test_tex.h b/test/unit/parsers/test_tex.h new file mode 100644 index 0000000..de0f02b --- /dev/null +++ b/test/unit/parsers/test_tex.h @@ -0,0 +1,19 @@ + +void test_tex_comments() { + test_parser_verify_parse( + test_parser_sourcefile("tex", " %comment"), + "tex", "", "%comment", 0 + ); +} + +void test_tex_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("tex", " %comment"), + "comment", "%comment" + ); +} + +void all_tex_tests() { + test_tex_comments(); + test_tex_comment_entities(); +} diff --git a/test/unit/parsers/test_vala.h b/test/unit/parsers/test_vala.h new file mode 100644 index 0000000..8811e0e --- /dev/null +++ b/test/unit/parsers/test_vala.h @@ -0,0 +1,23 @@ + +void test_vala_comments() { + test_parser_verify_parse( + test_parser_sourcefile("vala", " //comment"), + "vala", "", "//comment", 0 + ); +} + +void test_vala_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("vala", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("vala", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_vala_tests() { + test_vala_comments(); + test_vala_comment_entities(); +} diff --git a/test/unit/parsers/test_vb_aspx.h b/test/unit/parsers/test_vb_aspx.h new file mode 100644 index 0000000..f6971b6 --- /dev/null +++ b/test/unit/parsers/test_vb_aspx.h @@ -0,0 +1,12 @@ + +void test_vb_aspx_comment() { + test_parser_verify_parse2( + test_parser_sourcefile("vb_aspx", "<%\n 'comment\n%>"), + "html", "<%\n%>", "", 0, + "visualbasic", "", "'comment\n", 0 + ); +} + +void all_vb_aspx_tests() { + test_vb_aspx_comment(); +} diff --git a/test/unit/parsers/test_vhdl.h b/test/unit/parsers/test_vhdl.h new file mode 100644 index 0000000..d40ba96 --- /dev/null +++ b/test/unit/parsers/test_vhdl.h @@ -0,0 +1,19 @@ + +void test_vhdl_comments() { + test_parser_verify_parse( + test_parser_sourcefile("vhdl", " -- comment"), + "vhdl", "", "-- comment", 0 + ); +} + +void test_vhdl_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("vhdl", " --comment"), + "comment", "--comment" + ); +} + +void all_vhdl_tests() { + test_vhdl_comments(); + test_vhdl_comment_entities(); +} diff --git a/test/unit/parsers/test_visualbasic.h b/test/unit/parsers/test_visualbasic.h new file mode 100644 index 0000000..b86f7a2 --- /dev/null +++ b/test/unit/parsers/test_visualbasic.h @@ -0,0 +1,23 @@ + +void test_visualbasic_comments() { + test_parser_verify_parse( + test_parser_sourcefile("visualbasic", " 'comment"), + "visualbasic", "", "'comment", 0 + ); +} + +void test_visualbasic_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("visualbasic", " 'comment"), + "comment", "'comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("visualbasic", " Rem comment"), + "comment", "Rem comment" + ); +} + +void all_visualbasic_tests() { + test_visualbasic_comments(); + test_visualbasic_comment_entities(); +} diff --git a/test/unit/parsers/test_xaml.h b/test/unit/parsers/test_xaml.h new file mode 100644 index 0000000..ce11b52 --- /dev/null +++ b/test/unit/parsers/test_xaml.h @@ -0,0 +1,19 @@ + +void test_xaml_comments() { + test_parser_verify_parse( + test_parser_sourcefile("xaml", " "), + "xaml", "", "", 0 + ); +} + +void test_xaml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("xaml", " "), + "comment", "" + ); +} + +void all_xaml_tests() { + test_xaml_comments(); + test_xaml_comment_entities(); +} diff --git a/test/unit/parsers/test_xml.h b/test/unit/parsers/test_xml.h new file mode 100644 index 0000000..4cf9e35 --- /dev/null +++ b/test/unit/parsers/test_xml.h @@ -0,0 +1,19 @@ + +void test_xml_comments() { + test_parser_verify_parse( + test_parser_sourcefile("xml", " "), + "xml", "", "", 0 + ); +} + +void test_xml_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("xml", " "), + "comment", "" + ); +} + +void all_xml_tests() { + test_xml_comments(); + test_xml_comment_entities(); +} diff --git a/test/unit/parsers/test_xmlschema.h b/test/unit/parsers/test_xmlschema.h new file mode 100644 index 0000000..afad0b8 --- /dev/null +++ b/test/unit/parsers/test_xmlschema.h @@ -0,0 +1,19 @@ + +void test_xmlschema_comments() { + test_parser_verify_parse( + test_parser_sourcefile("xmlschema", " "), + "xmlschema", "", "", 0 + ); +} + +void test_xmlschema_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("xmlschema", " "), + "comment", "" + ); +} + +void all_xmlschema_tests() { + test_xmlschema_comments(); + test_xmlschema_comment_entities(); +} diff --git a/test/unit/parsers/test_xslt.h b/test/unit/parsers/test_xslt.h new file mode 100644 index 0000000..3bde5a3 --- /dev/null +++ b/test/unit/parsers/test_xslt.h @@ -0,0 +1,19 @@ + +void test_xslt_comments() { + test_parser_verify_parse( + test_parser_sourcefile("xslt", " "), + "xslt", "", "", 0 + ); +} + +void test_xslt_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("xslt", " "), + "comment", "" + ); +} + +void all_xslt_tests() { + test_xslt_comments(); + test_xslt_comment_entities(); +} diff --git a/test/unit/pascal_test.rb b/test/unit/pascal_test.rb deleted file mode 100644 index 1c0aa07..0000000 --- a/test/unit/pascal_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::PascalTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("pascal", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "pascal") - end - - def test_comprehensive - verify_parse("pascal1.pas") - verify_parse("pascal2.pp") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'pascal', :comment).first) - assert_equal('(*comment*)', entities_array(" (*comment*)", 'pascal', :comment).first) - assert_equal('{comment}', entities_array(" {comment}", 'pascal', :comment).first) - end -end diff --git a/test/unit/perl_test.rb b/test/unit/perl_test.rb deleted file mode 100644 index cfe8df5..0000000 --- a/test/unit/perl_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::PerlTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("perl", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "perl") - end - - def test_perl_in_cgi - verify_parse("perl.cgi") - end - - def test_comprehensive - verify_parse("perl1.pl") - end - - def test_comprehensive - verify_parse("perl_module.pm") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'perl', :comment).first) - assert_equal("=head1\ncomment\n=cut", entities_array("=head1\ncomment\n=cut", 'perl', :comment).first) - end -end diff --git a/test/unit/php_test.rb b/test/unit/php_test.rb deleted file mode 100644 index 56a99e0..0000000 --- a/test/unit/php_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::PhpTest < Ohcount::Test - def test_comment - lbhtml = Ohcount::LanguageBreakdown.new("html", "", "", 0) - lbphp = Ohcount::LanguageBreakdown.new("php", "", "//comment\n", 0) - assert_equal [lbhtml, lbphp], Ohcount::parse("", "php") - end - - def test_comprehensive - verify_parse("php1.php") - end - - def test_comment_entities - assert_equal('// comment', entities_array("\n", 'php', :comment).first) - assert_equal('/* comment */', entities_array("\n", 'php', :comment).first) - end -end diff --git a/test/unit/pike_test.rb b/test/unit/pike_test.rb deleted file mode 100644 index 102e487..0000000 --- a/test/unit/pike_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::PikeTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("pike", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "pike") - end - - def test_comments2 - lb = [Ohcount::LanguageBreakdown.new("pike", "", "/*comment*/", 0)] - assert_equal lb, Ohcount::parse(" /*comment*/", "pike") - end - - def test_comprehensive - verify_parse("pike1.pike") - end - - def test_comprehensive_pmod - verify_parse("pike2.pmod") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'pike', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'pike', :comment).first) - end -end diff --git a/test/unit/python/python_test.py b/test/unit/python/python_test.py new file mode 100644 index 0000000..6fbe254 --- /dev/null +++ b/test/unit/python/python_test.py @@ -0,0 +1,68 @@ +import unittest +import ohcount + +class TestSourceFileList(unittest.TestCase): + + def setUp(self): + # must not raise + self.sf_list = ohcount.SourceFileList(paths=['../../gestalt_files']) + + def assertStrOp(self, obj, not_equals): + s = str(obj) + if not_equals: + for v in not_equals: + self.assertTrue(s is not v) + + def assertHasAttr(self, obj, name, not_equals=None): + self.assertTrue(hasattr(obj, name)) + if not_equals: + val = getattr(obj, name) + for v in not_equals: + self.assertTrue(val is not v) + + def assertHasItem(self, obj, name, not_equals=None): + self.assertTrue(name in obj) + if not_equals: + val = obj[name] + for v in not_equals: + self.assertTrue(val is not v) + + def assertHasItemAttr(self, obj, name, not_equals=None): + self.assertHasAttr(obj, name, not_equals) + self.assertHasItem(obj, name, not_equals) + + def assertHasKeys(self, obj, keylist): + for k in keylist: + self.assertTrue(k in obj) + + def assertListIsInstance(self, list, type): + for o in list: + self.assertTrue(isinstance(o, type)) + + def assertHasItemAttrs(self, obj, list, not_equals=None): + for name in list: + self.assertHasItemAttr(obj, name, not_equals) + + def testList(self): + self.assertTrue(len(self.sf_list) > 0) + self.assertListIsInstance(self.sf_list, ohcount.SourceFile) + + def testStr(self): + self.assertStrOp(self.sf_list, [None, ""]) + + def testAnalyzeLanguages(self): + locs = self.sf_list.analyze_languages() + self.assertTrue(isinstance(locs, ohcount.LocList)) + names = ['code','comments','blanks','filecount','total'] + self.assertHasKeys(locs, names) + self.assertHasItemAttrs(locs, names, [None, 0]) + self.assertListIsInstance(locs, ohcount.Loc) + + def testAddDirectory(self): + self.sf_list.add_directory('../../detect_files') # must not raise + + def testAddFile(self): + self.sf_list.add_file('../../src_licenses/academic_t1.c') # must not raise + +if __name__ == '__main__': + unittest.main() diff --git a/test/unit/python_test.rb b/test/unit/python_test.rb deleted file mode 100644 index b666348..0000000 --- a/test/unit/python_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::PythonTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("python", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "python") - end - - def test_doc_comment - lb = [Ohcount::LanguageBreakdown.new("python", "", "'''\ndoc comment\n'''", 0)] - assert_equal lb, Ohcount::parse(" '''\n doc comment\n '''", "python") - end - - def test_strings - lb = [Ohcount::LanguageBreakdown.new("python", "\"abc#not a 'comment\"", "", 0)] - assert_equal lb, Ohcount::parse("\"abc#not a 'comment\"", "python") - end - - def test_comprehensive - verify_parse("py1.py") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'python', :comment).first) - assert_equal('"""comment"""', entities_array(" \"\"\"comment\"\"\"", 'python', :comment).first) - end -end diff --git a/test/unit/rexx_test.rb b/test/unit/rexx_test.rb deleted file mode 100644 index 82b1287..0000000 --- a/test/unit/rexx_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::RexxTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("rexx", "", "/*comment*/", 0)] - assert_equal lb, Ohcount::parse(" /*comment*/", "rexx") - end - - def test_comprehensive - verify_parse("rexx1.rex") - end - - def test_comment_entities - assert_equal('/*comment*/', entities_array(" /*comment*/", 'rexx', :comment).first) - end - -end diff --git a/test/unit/rhtml_test.rb b/test/unit/rhtml_test.rb deleted file mode 100644 index 117c351..0000000 --- a/test/unit/rhtml_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::RhtmlTest < Ohcount::Test - - def test_comment - html_lb = Ohcount::LanguageBreakdown.new("html", "<%\n%>", "", 0) - ruby_lb = Ohcount::LanguageBreakdown.new("ruby", "", "#comment\n", 0) - assert_equal [html_lb, ruby_lb], Ohcount::parse("<%\n #comment\n%>", "rhtml") - end - - def test_comprehensive - verify_parse("rhtml1.rhtml") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'rhtml', :comment).first) - assert_equal('/*comment*/', entities_array("", 'rhtml', :comment).first) - assert_equal('//comment', entities_array("", 'rhtml', :comment).first) - assert_equal('/*comment*/', entities_array("", 'rhtml', :comment).first) - assert_equal('#comment', entities_array("<%\n#comment\n%>", 'rhtml', :comment).first) - assert_equal("=begin\ncomment\n=end", entities_array("<%\n=begin\ncomment\n=end\n%>", 'rhtml', :comment).first) - end - -end diff --git a/test/unit/ruby/gestalt/csharp_using_rule_test.rb b/test/unit/ruby/gestalt/csharp_using_rule_test.rb new file mode 100644 index 0000000..182c0f4 --- /dev/null +++ b/test/unit/ruby/gestalt/csharp_using_rule_test.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class CSharpUsingRuleTest < Test::Unit::TestCase + include Ohcount::Gestalt + + + def test_sample + cs = SourceFile.new("hello.cs", :contents => <<-INLINE +using System; +using System.Foo; +using NUnit.Framework; + +namespace Hello +{ + /// Hi there +} + INLINE + ) + + r = CSharpUsingRule.new(/System/) + r.process_source_file(cs) + assert_equal 2, r.count + + r = CSharpUsingRule.new(/^System$/) + r.process_source_file(cs) + assert_equal 1, r.count + + r = CSharpUsingRule.new(/.+/) + r.process_source_file(cs) + assert_equal 3, r.count + + end +end diff --git a/test/unit/ruby/gestalt/definitions_test.rb b/test/unit/ruby/gestalt/definitions_test.rb new file mode 100644 index 0000000..ab78748 --- /dev/null +++ b/test/unit/ruby/gestalt/definitions_test.rb @@ -0,0 +1,429 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +include Ohcount +include Ohcount::Gestalt + +class DefinitionsTest < Ohcount::Test + + def test_zend_framework + assert_gestalts 'zend_framework', [ + Base.new(:platform,'php'), + Base.new(:platform,'zendframework'), + Base.new(:platform,'scripting') + ] + end + + def test_php + assert_gestalts 'php', [ + Base.new(:platform,'php'), + Base.new(:platform,'scripting') + ] + end + + def test_wx_widgets + assert_gestalts 'wx_widgets', [ + Base.new(:platform,'wxwidgets'), + Base.new(:platform, 'native_code') + ] + end + + def test_eclipse_platform + assert_gestalts 'eclipse_platform', [ + Base.new(:platform,'java'), + Base.new(:platform,'eclipseplatform') + ] + end + + def test_win32_not_enough + assert_gestalts 'win32_not_enough', [ + Base.new(:platform, 'native_code') + ] + end + + def test_win32_enough + assert_gestalts 'win32_enough', [ + Base.new(:platform, 'win32'), + Base.new(:platform, 'native_code') + ] + end + + def test_ruby_just_enough + assert_gestalts 'ruby_just_enough', [ + Base.new(:platform, 'ruby'), + Base.new(:platform, 'scripting'), + Base.new(:platform, 'native_code'), + ] + end + + def test_ruby_not_enough + assert_gestalts 'ruby_not_enough', [ + Base.new(:platform, 'native_code') + ] + end + + def test_cakephp + assert_gestalts 'cakephp', [ + Base.new(:platform, 'php'), + Base.new(:platform, 'cakephp'), + Base.new(:platform, 'scripting'), + ] + end + + def test_symfony + assert_platform('symfony', :php, :symfony, :scripting) + end + + def test_pear + assert_platform('pear', :php, :pear, :scripting) + end + + def test_moodle + assert_platform('moodle', :php, :moodle, :scripting) + end + + def test_spring_framework + assert_gestalts 'spring_framework', [ + Base.new(:platform, 'java'), + Base.new(:platform, 'springframework') + ] + end + + def test_rails + assert_platform('rails', :ruby, :rails, :scripting) + end + + def test_jquery + assert_platform('jquery', :javascript, :jquery, :scripting) + end + + def test_dojo + h = SourceFile.new("sample.html", :contents => '') + expected_gestalts = [ Base.new(:platform, "dojo") ] + assert_equal expected_gestalts.sort, h.gestalts.sort + end + + def test_yui + h = SourceFile.new("sample.html", :contents => '') + expected_gestalts = [ Base.new(:platform, "yui") ] + assert_equal expected_gestalts.sort, h.gestalts.sort + end + + def test_python + assert_platform('python', :python, :scripting) + end + + def test_mac + assert_platform('mac', :mac, :native_code) + end + + def test_plist + assert_platform('plist', :mac) + end + + def test_posix + assert_platform('posix', :posix, :native_code) + end + + def test_x_windows + assert_platform('xwindows', :xwindows, :native_code) + end + + def test_kde + assert_platform('kde', :kde, :native_code) + end + + def test_msdos + assert_platform('msdos', :msdos, :native_code) + end + + def test_gtk + assert_platform('gtk', :gtk, :native_code) + end + + def test_drupal + assert_platform('drupal', :php, :drupal, :scripting) + end + + def test_vs_1 + assert_tool('vs_1', :visualstudio) + end + + def test_eclipse + assert_tool('eclipse', :eclipse) + end + + def test_netbeans + assert_tool('netbeans', :netbeans) + end + + def test_arm + asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM + orrs 3, eax + INLINE_ASM + ) + + expected_gestalts = [ + Base.new(:platform, 'arm') + ] + + assert_equal expected_gestalts.sort, asm.gestalts.sort + end + + def test_arm_from_c_keywords + c = SourceFile.new("foo.c", :contents => <<-INLINE_C + #define __arm__ + INLINE_C + ) + expected_gestalts = [ + Base.new(:platform, 'arm'), + Base.new(:platform, 'native_code') + ] + assert_equal expected_gestalts, c.gestalts + end + + def test_arm_neon + asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM + vmov u8, s + INLINE_ASM + ) + + expected_gestalts = [ + Base.new(:platform, 'arm'), + Base.new(:platform, 'arm_neon') + ] + + assert_equal expected_gestalts.sort, asm.gestalts.sort + end + + def test_moblin_clutter + c = SourceFile.new("foo.c", :contents => <<-INLINE_C + clutter_actor_queue_redraw (CLUTTER_ACTOR(label)); + INLINE_C + ) + expected_gestalts = [ + Base.new(:platform, 'clutter'), + Base.new(:platform, 'moblin'), + Base.new(:platform, 'mid_combined'), + Base.new(:platform, 'native_code') + ] + + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + def test_moblin_by_filename + c = SourceFile.new("moblin-netbook-system-tray.h", :contents => <<-INLINE_PERL + #include "foo" + INLINE_PERL + ) + expected_gestalts = [ + Base.new(:platform, 'moblin_misc'), + Base.new(:platform, 'moblin'), + Base.new(:platform, 'mid_combined'), + Base.new(:platform, 'native_code') + ] + + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + def test_moblin_by_keyword + c = SourceFile.new("foo.c", :contents => <<-INLINE_PERL + proxy = dbus_g_proxy_new_for_name (conn, "org.moblin.connman", + INLINE_PERL + ) + expected_gestalts = [ + Base.new(:platform, 'moblin_misc'), + Base.new(:platform, 'moblin'), + Base.new(:platform, 'mid_combined'), + Base.new(:platform, 'native_code') + ] + + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + def test_nbtk + c = SourceFile.new("foo.c", :contents => <<-INLINE_C + button = nbtk_button_new_with_label ("Back"); + INLINE_C + ) + expected_gestalts = [ + Base.new(:platform, 'nbtk'), + Base.new(:platform, 'mid_combined'), + Base.new(:platform, 'moblin'), + Base.new(:platform, 'native_code') + ] + + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + + def test_android + java = SourceFile.new("foo.java", :contents => <<-INLINE_C + import android.app.Activity; + // import dont.import.this; + INLINE_C + ) + + names = java.gestalts.map { |g| g.name if g.type == :platform }.compact + assert names.include?('java') + assert names.include?('android') + assert names.include?('mid_combined') + end + + def test_iphone + objective_c = SourceFile.new("foo.m", :contents => <<-OBJECTIVE_C + #import + #import + #import "WhackABugApp.h" + + int main(int argc, char *argv[]) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + int ret = UIApplicationMain(argc, argv, [WhackABugApp class]); + [pool release]; + return ret; + } + OBJECTIVE_C + ) + + expected_gestalts = [ + Base.new(:platform, 'iphone'), + Base.new(:platform, 'mid_combined') + ] + + assert_equal expected_gestalts.sort, objective_c.gestalts.sort + end + + def test_hildon + c = SourceFile.new("foo.c", :contents => <<-INLINE_C + HildonWindow *window; + INLINE_C + ) + expected_gestalts = [ + Base.new(:platform, 'hildon'), + Base.new(:platform, 'maemo'), + Base.new(:platform, 'native_code'), + Base.new(:platform, 'mid_combined') + ] + + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + def test_atom_linux + make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE + COMPILE_FLAGS=/QxL + INLINE_MAKEFILE + ) + expected_gestalts = [ + Base.new(:platform, 'xl_flag'), + Base.new(:platform, 'atom') + ] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_atom_windows + make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE + CCFLAGS = -xL + INLINE_MAKEFILE + ) + expected_gestalts = [ + Base.new(:platform, 'xl_flag'), + Base.new(:platform, 'atom') + ] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_not_atom_windows + make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE + CCFLAGS = -xLo + INLINE_MAKEFILE + ) + expected_gestalts = [] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_atom_sse3 + make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE + COMPILE_FLAGS=-xSSE3_ATOM_FLAG + INLINE_MAKEFILE + ) + expected_gestalts = [ + Base.new(:platform, 'sse3_atom_flag'), + Base.new(:platform, 'atom') + ] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_intel_compiler + + make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE + CC = icc + INLINE_MAKEFILE + ) + expected_gestalts = [ + Base.new(:platform, 'intel_compiler'), + ] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_opensso + java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA +import com.sun.identity.authentication; + INLINE_JAVA + ) + platforms = java.gestalts.map { |g| g.name if g.type == :platform }.compact + assert platforms.include?('java') + assert platforms.include?('opensso') + end + + def test_windows_ce + csharp = SourceFile.new("bam.cs", :contents => <<-INLINE_CSHARP + using System; + using Microsoft.WindowsMobile.DirectX; + INLINE_CSHARP + ) + expected_gestalts = [ + Base.new(:platform, 'windows_ce_incomplete'), + Base.new(:platform, 'dot_net'), + ] + + assert_equal expected_gestalts.sort, csharp.gestalts.sort + end + + def test_gcc + make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE + CC = gcc + INLINE_MAKEFILE + ) + expected_gestalts = [ + Base.new(:platform, 'gcc'), + ] + assert_equal expected_gestalts.sort, make.gestalts.sort + end + + def test_native_code + c = SourceFile.new("foo.c", :contents => <<-INLINE_C + int *pcode = NULL; + INLINE_C + ) + expected_gestalts = [ + Base.new(:platform, 'native_code'), + ] + assert_equal expected_gestalts.sort, c.gestalts.sort + end + + def test_flash + as = SourceFile.new("sample.as", :contents => 'greet.text = "Hello, world";') + expected_gestalts = [ Base.new(:platform, "flash") ] + assert_equal expected_gestalts.sort, as.gestalts.sort + end + + def test_flex + as = SourceFile.new("sample.mxml", :contents => <<-MXML + + + MXML + ) + expected_gestalts = [ Base.new(:platform, 'flex') ] + assert_equal expected_gestalts.sort, as.gestalts.sort + end +end diff --git a/test/unit/ruby/gestalt/dot_net_definitions_test.rb b/test/unit/ruby/gestalt/dot_net_definitions_test.rb new file mode 100644 index 0000000..c54f955 --- /dev/null +++ b/test/unit/ruby/gestalt/dot_net_definitions_test.rb @@ -0,0 +1,48 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' +include Ohcount +include Ohcount::Gestalt + +class DotNetDefinitionsTest < Ohcount::Test + + def test_wpf + platforms = get_gestalts('wpf').map { |g| g.name if g.type == :platform }.compact + assert platforms.include?("dot_net") + assert platforms.include?("wpf") + end + + def test_asp_net + platforms = get_gestalts('asp_net').map { |g| g.name if g.type == :platform }.compact + assert platforms.include?("dot_net") + assert platforms.include?("asp_net") + end + + + def test_silverlight_via_asp_keyword + sf = SourceFile.new('foo.aspx', :contents => <<-CONTENTS + + + +CONTENTS + ) + platforms = sf.gestalts.map { |g| g.name if g.type == :platform }.compact + assert platforms.include?('dot_net') + assert platforms.include?('asp_net') + assert platforms.include?('silverlight') + end + + def test_silverlight_via_csproj_import + sf = SourceFile.new('Foo.csproj', :contents => <<-CONTENTS + + + + CONTENTS + ) + platforms = sf.gestalts.map { |g| g.name if g.type == :platform }.compact + assert platforms.include?('dot_net') + assert platforms.include?('silverlight') + + tools = sf.gestalts.map { |g| g.name if g.type == :tool }.compact + assert tools.include?('visualstudio') + end +end diff --git a/test/unit/ruby/gestalt/file_rule_test.rb b/test/unit/ruby/gestalt/file_rule_test.rb new file mode 100644 index 0000000..0274bf6 --- /dev/null +++ b/test/unit/ruby/gestalt/file_rule_test.rb @@ -0,0 +1,54 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +class FileRuleTest < Test::Unit::TestCase + include Ohcount::Gestalt + + def test_initialize + r = FileRule.new(:min => 5) + assert_equal 5, r.min_count + end + + def test_initialize_wrong_args + assert_raise ArgumentError do + r = FileRule.new(:boo => 1) + end + end + +# def test_trigger_c_header +# r = Ohcount::Gestalt::CHeaderRule.new('foo.h') +# s = Ohcount::SourceFile.new('header.h', :contents => <<-H_FILE +# // a comment +# include 'foo.h' +# H_FILE +# ) +# assert r.trigger_file?(s) +# end +# +# def test_c_keyword_rule +# r = Ohcount::Gestalt::CKeywordRule.new('WM_PAINT') +# s = Ohcount::SourceFile.new('header.h', :contents => <<-H_FILE +# // a comment +# (WM_PAINT) +# H_FILE +# ) +# assert r.trigger_file?(s) +# end +# +# def test_filename_rule +# r = Ohcount::Gestalt::FilenameRule.new('header.h') +# s = Ohcount::SourceFile.new('header.h') +# assert r.trigger_file?(s) +# end +# +# def test_filename_rule_advanced +# r = Ohcount::Gestalt::FilenameRule.new('f[ab]o', 'foo') +# assert r.trigger_file?(Ohcount::SourceFile.new('fao')) +# assert r.trigger_file?(Ohcount::SourceFile.new('fbo')) +# assert r.trigger_file?(Ohcount::SourceFile.new('foo')) +# assert !r.trigger_file?(Ohcount::SourceFile.new('fco')) +# end +end + + + diff --git a/test/unit/ruby/gestalt/filename_rule_test.rb b/test/unit/ruby/gestalt/filename_rule_test.rb new file mode 100644 index 0000000..5992f70 --- /dev/null +++ b/test/unit/ruby/gestalt/filename_rule_test.rb @@ -0,0 +1,19 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +class FilenameRuleTest < Test::Unit::TestCase + include Ohcount::Gestalt + + def test_process_file + r = FilenameRule.new('foo\.rb') + s = Ohcount::SourceFile.new('/bar/com/foo.rb', :contents => <<-RUBY_CODE + # comment + code = 1 + RUBY_CODE + ) + assert r.process_source_file(s) + assert_equal 1, r.count + end +end + + diff --git a/test/unit/ruby/gestalt/gestalt_test.rb b/test/unit/ruby/gestalt/gestalt_test.rb new file mode 100644 index 0000000..ee4f066 --- /dev/null +++ b/test/unit/ruby/gestalt/gestalt_test.rb @@ -0,0 +1,10 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../test_helper.rb' +require File.dirname(__FILE__) + '/file_rule_test' +require File.dirname(__FILE__) + '/filename_rule_test' +require File.dirname(__FILE__) + '/keyword_rule_test' +require File.dirname(__FILE__) + '/rule_test' +require File.dirname(__FILE__) + '/definitions_test' +require File.dirname(__FILE__) + '/java_definitions_test' +require File.dirname(__FILE__) + '/dot_net_definitions_test' +require File.dirname(__FILE__) + '/jasper_definitions_test' diff --git a/test/unit/ruby/gestalt/jasper_definitions_test.rb b/test/unit/ruby/gestalt/jasper_definitions_test.rb new file mode 100644 index 0000000..8eef510 --- /dev/null +++ b/test/unit/ruby/gestalt/jasper_definitions_test.rb @@ -0,0 +1,117 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../test_helper.rb' + +include Ohcount +include Ohcount::Gestalt + +class DefinitionsTest < Ohcount::Test + + def test_jasper_reports_java + java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA + public class Employee implements Serializable { + private net.sf.jasperreports.report myReport; + } + INLINE_JAVA + ) + assert platform_names(java.gestalts).include?('jaspersoft') + assert platform_names(java.gestalts).include?('jasper_reports') + assert platform_names(java.gestalts).include?('jasper_reports_java') + end + + def test_jasper_reports_via_maven + java = SourceFile.new("pom.xml", :contents => <<-INLINE_POM + + dzrealms + HelloWorld + 1.0 + + + jasperreports + jasperreports + 2.0.5 + + + + INLINE_POM + ) + assert platform_names(java.gestalts).include?('jaspersoft') + assert platform_names(java.gestalts).include?('jasper_reports') + assert platform_names(java.gestalts).include?('jasper_reports_java') + end + + def test_jasper_server_java + java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA + public class Employee implements Serializable { + private com.jaspersoft.jasperserver; + } + INLINE_JAVA + ) + assert platform_names(java.gestalts).include?('jaspersoft') + assert platform_names(java.gestalts).include?('jasper_server') + assert platform_names(java.gestalts).include?('jasper_server_java') + end + + def test_jasper_intelligence + java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA + public class Employee implements Serializable { + private com.jaspersoft.ji; + } + INLINE_JAVA + ) + assert platform_names(java.gestalts).include?('jaspersoft') + assert platform_names(java.gestalts).include?('jasper_intelligence') + end + + def test_jasper_server + expected = ['scripting', 'ruby', 'jaspersoft', 'jasper_server', 'jasper_server_keyword'] + + rb = SourceFile.new('jasper.rb', :contents => 'def jasper_server; nil ; end') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'def jasperserver; nil ; end') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'js = JasperServer.new()') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'jasper-server') + assert_platforms(expected, rb.gestalts) + end + + def test_jasper_reports + expected = ['scripting', 'ruby', 'jaspersoft', 'jasper_reports', 'jasper_reports_keyword'] + + rb = SourceFile.new('jasper.rb', :contents => 'def jasper_reports; nil ; end') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'def jasperreports; nil ; end') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'def JasperReport; nil ; end') + assert_platforms(expected, rb.gestalts) + + rb = SourceFile.new('jasper.rb', :contents => 'jasper-report') + assert_platforms(expected, rb.gestalts) + end + + def test_jasper_ireport + rb = SourceFile.new('jasper.rb', :contents => 'ireport = nil') + assert !platform_names(rb.gestalts).include?('jasper_ireport') + + rb = SourceFile.new('jasper.rb', :contents => 'jasper = nil') + assert !platform_names(rb.gestalts).include?('jasper_ireport') + + rb = SourceFile.new('jasper.rb', :contents => 'jasper_ireport = nil') + assert platform_names(rb.gestalts).include?('jasper_ireport') + end + + protected + + def assert_platforms(expected_names, actual) + assert_equal(expected_names.sort, platform_names(actual).sort) + end + + def platform_names(gestalts) + gestalts.map { |g| g.type == :platform && g.name }.compact + end +end diff --git a/test/unit/ruby/gestalt/java_definitions_test.rb b/test/unit/ruby/gestalt/java_definitions_test.rb new file mode 100644 index 0000000..f3a3bb1 --- /dev/null +++ b/test/unit/ruby/gestalt/java_definitions_test.rb @@ -0,0 +1,75 @@ +include Ohcount +include Ohcount::Gestalt +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +class JavaDefinitionsTest < Ohcount::Test + + def test_weblogic_via_maven + assert_gestalts 'weblogic_maven', [ + Base.new(:platform, 'appserver'), + Base.new(:platform, 'java'), + Base.new(:platform, 'maven'), + Base.new(:platform, 'weblogic') + ] + end + + def test_weblogic_via_descriptor + assert_gestalts 'weblogic_descriptor', [ + Base.new(:platform, 'appserver'), + Base.new(:platform, 'java'), + Base.new(:platform, 'weblogic') + ] + end + + def test_webshpere_via_descriptor + assert_gestalts 'websphere', [ + Base.new(:platform, 'appserver'), + Base.new(:platform, 'java'), + Base.new(:platform, 'websphere') + ] + end + + def test_ejb30_by_default + sf = SourceFile.new('hello.java', :contents => <<-JAVA + @Stateless + public class HelloBean { } + JAVA + ) + assert_equal [ + Base.new(:platform, 'java'), + Base.new(:platform, 'ejb3+'), + Base.new(:platform, 'ejb3.0') + ].sort, sf.gestalts.sort + end + + + def test_ejb31_through_annotation + sf = SourceFile.new('hello.java', :contents => <<-JAVA + @Stateless + public class HelloBean { + @Asynchronous public Future getHelloValue() {} + } + JAVA + ) + assert_equal [ + Base.new(:platform, 'java'), + Base.new(:platform, 'ejb3+'), + Base.new(:platform, 'ejb3.1') + ].sort, sf.gestalts.sort + end + + def test_ejb31_through_global_jndi + sf = SourceFile.new('hello.java', :contents => <<-JAVA + public class PlaceBidClient { + context.lookup("java:global/action-bazaar/PlaceBid"); + } + JAVA + ) + assert_equal [ + Base.new(:platform, 'java'), + Base.new(:platform, 'ejb3+'), + Base.new(:platform, 'ejb3.1') + ].sort, sf.gestalts.sort + end + +end diff --git a/test/unit/ruby/gestalt/keyword_rule_test.rb b/test/unit/ruby/gestalt/keyword_rule_test.rb new file mode 100644 index 0000000..dc5098e --- /dev/null +++ b/test/unit/ruby/gestalt/keyword_rule_test.rb @@ -0,0 +1,44 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +class KeywordRuleTest < Test::Unit::TestCase + include Ohcount::Gestalt + + def test_process_file_in_same_language + r = KeywordRule.new('c', 'WIN32') + s = Ohcount::SourceFile.new('header.c', :contents => <<-C_CODE + // a comment + #ifdef WIN32 + ..some code.. + #endif + C_CODE + ) + r.process_source_file(s) + assert_equal 1, r.count + end + + def test_process_file_in_other_language + r = KeywordRule.new('java', 'WIN32') + s = Ohcount::SourceFile.new('header.c', :contents => <<-C_CODE + // a comment + #ifdef WIN32 + ..some code.. + #endif + C_CODE + ) + r.process_source_file(s) + assert_equal 0, r.count + end + + def test_process_file_with_any_language + r = KeywordRule.new(nil, 'A', 'B') + s = Ohcount::SourceFile.new('mixed.rhtml', :contents => <<-RHTML + <% some ruby containing A -%> +
B
+ RHTML + ) + r.process_source_file(s) + assert_equal 2, r.count + end +end + diff --git a/test/unit/ruby/gestalt/maven_dependency_rule_test.rb b/test/unit/ruby/gestalt/maven_dependency_rule_test.rb new file mode 100644 index 0000000..332dee3 --- /dev/null +++ b/test/unit/ruby/gestalt/maven_dependency_rule_test.rb @@ -0,0 +1,60 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class MavenDependencyTest < Test::Unit::TestCase + include Ohcount::Gestalt + + + def test_dependency + pom = SourceFile.new("pom.xml", :contents => <<-INLINE + + + + + test_group_1 + test_artifact_1A + + + test_group_1 + test_artifact_1B + + + test_group_2 + test_artifact_2A + + + test_group_2 + test_artifact_2B + + + + INLINE + ) + + r = MavenRule.new('dependency', /1$/, /B$/) + + r.process_source_file(pom) + assert_equal 1, r.count + + end + + def test_plugin + pom = SourceFile.new("pom.xml", :contents => <<-INLINE + + + + foobar + baz + + + + INLINE + ) + + r = MavenRule.new('plugin', /^foobar\b/, /^baz\b/) + + r.process_source_file(pom) + assert_equal 1, r.count + end +end diff --git a/test/unit/ruby/gestalt/rule_test.rb b/test/unit/ruby/gestalt/rule_test.rb new file mode 100644 index 0000000..459bd18 --- /dev/null +++ b/test/unit/ruby/gestalt/rule_test.rb @@ -0,0 +1,11 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../../ruby/gestalt' + +class RuleTest < Test::Unit::TestCase + + def test_here + + end +end + + diff --git a/test/unit/ruby/ruby_test.rb b/test/unit/ruby/ruby_test.rb new file mode 100644 index 0000000..7b44cee --- /dev/null +++ b/test/unit/ruby/ruby_test.rb @@ -0,0 +1,4 @@ +require File.dirname(__FILE__) + '/test_helper.rb' +require File.dirname(__FILE__) + '/source_file_list_test.rb' +require File.dirname(__FILE__) + '/source_file_test.rb' +require File.dirname(__FILE__) + '/gestalt/gestalt_test' diff --git a/test/unit/ruby/source_file_list_test.rb b/test/unit/ruby/source_file_list_test.rb new file mode 100644 index 0000000..90d8ba6 --- /dev/null +++ b/test/unit/ruby/source_file_list_test.rb @@ -0,0 +1,34 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../../ruby/gestalt' + +class SourceFileListTest < Test::Unit::TestCase + + def test_source_file_list_supports_analyze + paths = [File.dirname(__FILE__)] + list = Ohcount::SourceFileList.new(:paths => paths) + assert list.size > 0 + # assume: the paths variable points to the directory containing this and other simple ruby test files + + ruby = Ohcount::Gestalt::Base.new(:platform, 'ruby') + scripting = Ohcount::Gestalt::Base.new(:platform, 'scripting') + + list.analyze(:gestalt) # this should work + assert list.gestalts.include?(ruby) + assert list.gestalts.include?(scripting) + + list.each do |filename| + assert_equal String, filename.class + end + end +end + +class SourceFileTest < Test::Unit::TestCase + def test_source_file_filenames + filenames = ["x", "y", "z"] + sf = Ohcount::SourceFile.new("foo", :contents => "bar", :filenames => filenames) + assert_equal filenames, sf.filenames + sf.each do |filename| + assert filenames.include?(filename) + end + end +end diff --git a/test/unit/ruby/source_file_test.rb b/test/unit/ruby/source_file_test.rb new file mode 100644 index 0000000..83a1af1 --- /dev/null +++ b/test/unit/ruby/source_file_test.rb @@ -0,0 +1,25 @@ +require 'test/unit' +require_relative '../../../ruby/gestalt' + +class SourceFileTest < Test::Unit::TestCase + def test_diff + optimer = File.open(File.dirname(__FILE__) + "/../../src_dir/optimer").read + new = Ohcount::SourceFile.new("optimer", :contents => optimer, :filenames => nil, :filenames => ["optimer"]) + old = Ohcount::SourceFile.new("optimer", :contents => "", :filenames => ["optimer"]) + assert_equal optimer, new.contents + deltas = old.diff(new).loc_deltas + assert_not_nil deltas + assert_equal "shell", deltas.first.language + end + + def test_empty_diff + filename = "mysql-stale-table-sniper" + c = File.open(File.dirname(__FILE__) + "/../../src_dir/#{filename}").read + new = Ohcount::SourceFile.new(filename, :contents => c, :filenames => nil, :filenames => [filename]) + old = Ohcount::SourceFile.new(filename, :contents => "", :filenames => nil, :filenames => [filename]) + assert_equal c, new.contents + deltas = old.diff(new).loc_deltas + assert_not_nil deltas + assert_equal "perl", deltas.first.language + end +end diff --git a/test/unit/ruby/test_helper.rb b/test/unit/ruby/test_helper.rb new file mode 100644 index 0000000..a43a4d2 --- /dev/null +++ b/test/unit/ruby/test_helper.rb @@ -0,0 +1,64 @@ +require 'test/unit' +require 'fileutils' +require 'find' +require File.dirname(__FILE__) + '/../../../ruby/ohcount.rb' # .rb is to specify the .rb instead of .bundle +require File.dirname(__FILE__) + '/../../../ruby/gestalt' # .rb is to specify the .rb instead of .bundle + +unless defined?(TEST_DIR) + TEST_DIR = File.dirname(__FILE__) +end + +module Ohcount +end + +# Ohcount::Test is a base class which includes several helper methods for parser testing. +# All unit tests in Ohcount should derive from this class. +# +# ==== Manual Testing +# +# To manually test a parser, rebuild ohcount and run it against your test file: +# +# rake +# bin/ohcount --annotate test/src_dir/my_file.ext +# +# The +annotate+ option will emit your test file to the console, and each line will be +# labeled as code, comment, or blank. +# +class Ohcount::Test < Test::Unit::TestCase + + # For reasons unknown, the base class defines a default_test method to throw a failure. + # We override it with a no-op to prevent this 'helpful' feature. + def default_test; end + + protected + + def assert_tool(path, *tools) + gestalts = tools.map do |t| + Base.new(:tool, t.to_s) + end + assert_gestalts path, gestalts + end + + def assert_platform(path, *platforms) + gestalts = platforms.map do |p| + Base.new(:platform, p.to_s) + end + assert_gestalts path, gestalts + end + + def assert_gestalts(path, expected_gestalts) + assert_equal expected_gestalts.sort, get_gestalts(path) + end + + def get_gestalts(path) + sfl = SourceFileList.new(:paths => [test_dir(path)]) + assert sfl.size > 0 + sfl.analyze(:gestalt) + sfl.gestalts.sort + end + + def test_dir(d) + File.expand_path(File.dirname(__FILE__) + "/../../gestalt_files/#{ d }") + end +end + diff --git a/test/unit/ruby_test.rb b/test/unit/ruby_test.rb deleted file mode 100644 index 805d052..0000000 --- a/test/unit/ruby_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::RubyTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("ruby", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "ruby") - end - - def test_comprehensive - verify_parse("ruby1.rb") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'ruby', :comment).first) - assert_equal("=begin\ncomment\n=end", entities_array("=begin\ncomment\n=end", 'ruby', :comment).first) - end - -end diff --git a/test/unit/scala_test.rb b/test/unit/scala_test.rb deleted file mode 100644 index 8d8c6c1..0000000 --- a/test/unit/scala_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ScalaTest < Ohcount::Test - - def test_comprehensive - verify_parse("scala1.scala") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'scala', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'scala', :comment).first) - end - -end diff --git a/test/unit/scheme_test.rb b/test/unit/scheme_test.rb deleted file mode 100644 index 37b4847..0000000 --- a/test/unit/scheme_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::SchemeTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("scheme", "", ";;; comment", 0)] - assert_equal lb, Ohcount::parse(" ;;; comment", "scheme") - end - - def test_comprehensive - verify_parse("scheme.scm") - end - - def test_comment_entities - assert_equal(';comment', entities_array(" ;comment", 'scheme', :comment).first) - end - -end diff --git a/test/unit/shell_test.rb b/test/unit/shell_test.rb deleted file mode 100644 index ac82410..0000000 --- a/test/unit/shell_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ShellTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("shell", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "shell") - end - - def test_comprehensive - verify_parse("sh1.sh") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'shell', :comment).first) - end -end diff --git a/test/unit/smalltalk_test.rb b/test/unit/smalltalk_test.rb deleted file mode 100644 index 18505b1..0000000 --- a/test/unit/smalltalk_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::SmalltalkTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("smalltalk", "", '"comment\\"', 0)] - assert_equal lb, Ohcount::parse(' "comment\\"', "smalltalk") - end - - def test_comprehensive - verify_parse("smalltalk1.st") - end - - def test_comment_entities - assert_equal('"comment"', entities_array(" \"comment\"", 'smalltalk', :comment).first) - end - -end diff --git a/test/unit/sourcefile_test.h b/test/unit/sourcefile_test.h new file mode 100644 index 0000000..f780675 --- /dev/null +++ b/test/unit/sourcefile_test.h @@ -0,0 +1,261 @@ +// sourcefile_test.h written by Mitchell Foral. mitchellcaladbolg.net. +// See COPYING for license information. + +#include +#include + +#include "../../src/sourcefile.h" +#include "../../src/diff.h" +#include "../../src/loc.h" + +void test_sourcefile_initialize() { + SourceFile *sf = ohcount_sourcefile_new("foo.rb"); + assert(strcmp("foo.rb", sf->filepath) == 0); + assert(strcmp("rb", sf->ext) == 0); + assert(strcmp("foo.rb", sf->filename) == 0); + assert(strncmp("", sf->filepath, sf->dirpath) == 0); + assert(sf->contents == NULL); + ohcount_sourcefile_free(sf); + + sf = ohcount_sourcefile_new("foo/bar.rb"); + assert(strcmp("foo/bar.rb", sf->filepath) == 0); + assert(strcmp("rb", sf->ext) == 0); + assert(strcmp("bar.rb", sf->filename) == 0); + assert(strncmp("foo/", sf->filepath, sf->dirpath) == 0); + assert(sf->contents == NULL); + ohcount_sourcefile_free(sf); +} + +void test_sourcefile_language_breakdowns() { + SourceFile *sf = ohcount_sourcefile_new("foo.rb"); + ohcount_sourcefile_set_contents(sf, "x = 5"); + ParsedLanguageList *list = ohcount_sourcefile_get_parsed_language_list(sf); + assert(strcmp("ruby", list->head->pl->name) == 0); + assert(strcmp("x = 5", list->head->pl->code) == 0); + ohcount_sourcefile_free(sf); +} + +void test_sourcefile_diff() { + SourceFile *old = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(old, "int i;"); + SourceFile *new = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(new, "int j;"); + LocDelta *delta1 = ohcount_loc_delta_new("c", 1, 1, 0, 0, 0, 0); + LocDelta *delta2 = ohcount_sourcefile_calc_loc_delta(old, "c", new); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + LocDeltaList *list1 = ohcount_loc_delta_list_new(); + ohcount_loc_delta_list_add_loc_delta(list1, delta1); + LocDeltaList *list2 = ohcount_sourcefile_diff(old, new); + assert(list1->head != NULL); + assert(list2->head != NULL); + assert(list1->head->next == NULL); + assert(list2->head->next == NULL); + assert(ohcount_loc_delta_is_equal(list1->head->delta, list2->head->delta)); + ohcount_sourcefile_free(old); + ohcount_sourcefile_free(new); + ohcount_loc_delta_free(delta1); + ohcount_loc_delta_free(delta2); + ohcount_loc_delta_list_free(list1); + ohcount_loc_delta_list_free(list2); +} + +void test_sourcefile_calc_diff2() { + SourceFile *old = ohcount_sourcefile_new("foo.html"); + ohcount_sourcefile_set_contents(old, + "\n" + " \n" + " \n" + "" + ); + SourceFile *new = ohcount_sourcefile_new("foo.html"); + ohcount_sourcefile_set_contents(new, + "\n" + " \n" + " \n" + "" + ); + LocDeltaList *list = ohcount_sourcefile_diff(old, new); + assert(strcmp(list->head->delta->language, "html") == 0); + assert(strcmp(list->head->next->delta->language, "javascript") == 0); + assert(strcmp(list->head->next->next->delta->language, "css") == 0); + LocDelta *delta1 = ohcount_loc_delta_new("javascript", 1, 1, 0, 0, 0, 0); + LocDelta *delta2 = ohcount_loc_delta_list_get_loc_delta(list, "javascript"); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + ohcount_loc_delta_free(delta1); + delta1 = ohcount_loc_delta_new("css", 0, 0, 1, 1, 0, 0); + delta2 = ohcount_loc_delta_list_get_loc_delta(list, "css"); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + ohcount_sourcefile_free(old); + ohcount_sourcefile_free(new); + ohcount_loc_delta_list_free(list); + ohcount_loc_delta_free(delta1); +} + +void test_sourcefile_diff_longer() { + SourceFile *old = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(old, + "int = 1;\n" + "int = 2;\n" + "int = 3;\n" + "int = 4;\n" + ); + SourceFile *new = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(new, + "int = 1;\n" + "int = 5;\n" + "int = 6;\n" + "int = 4;\n" + ); + LocDeltaList *list = ohcount_sourcefile_diff(old, new); + LocDelta *delta1 = ohcount_loc_delta_new("c", 2, 2, 0, 0, 0, 0); + LocDelta *delta2 = ohcount_loc_delta_list_get_loc_delta(list, "c"); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + ohcount_sourcefile_free(old); + ohcount_sourcefile_free(new); + ohcount_loc_delta_list_free(list); + ohcount_loc_delta_free(delta1); +} + +void test_sourcefile_diff_very_long() { + int len = 5500000; + char *a = malloc(len); + memset(a, 'i', len); + a[len-1] = '\0'; + a[len-2] = '\n'; + + SourceFile *old = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(old, a); + strncpy(a, "int = 1;\n", strlen("int = 1;\n")); + SourceFile *new = ohcount_sourcefile_new("foo.c"); + ohcount_sourcefile_set_contents(new, a); + LocDeltaList *list = ohcount_sourcefile_diff(old, new); + // 2 lines added, 1 removed... strange but thats the expectation + LocDelta *delta1 = ohcount_loc_delta_new("c", 2, 1, 0, 0, 0, 0); + LocDelta *delta2 = ohcount_loc_delta_list_get_loc_delta(list, "c"); + assert(ohcount_loc_delta_is_equal(delta1, delta2)); + ohcount_sourcefile_free(old); + ohcount_sourcefile_free(new); + ohcount_loc_delta_list_free(list); + ohcount_loc_delta_free(delta1); +} + +void test_sourcefile_calc_diff() { + int added, removed; + ohcount_calc_diff("", "", &added, &removed); + assert(added == 0); + assert(removed == 0); + ohcount_calc_diff("a", "a", &added, &removed); + assert(added == 0); + assert(removed == 0); + ohcount_calc_diff("a\n", "a\n", &added, &removed); + assert(added == 0); + assert(removed == 0); + ohcount_calc_diff("", "a\n", &added, &removed); + assert(added == 1); + assert(removed == 0); + ohcount_calc_diff("a\n", "", &added, &removed); + assert(added == 0); + assert(removed == 1); + ohcount_calc_diff("a\n", "b\n", &added, &removed); + assert(added = 1); + assert(removed == 1); + ohcount_calc_diff("a\nb\nc\n", "a\nc\nd\n", &added, &removed); + assert(added == 1); + assert(removed == 1); + + ohcount_calc_diff( + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n", // 10 times + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n" + "Hello, World!\n", // 11 times + &added, &removed + ); + assert(added == 1); + assert(removed == 0); +} + +void test_sourcefile_list_language_facts() { + SourceFileList *sfl = ohcount_sourcefile_list_new(); + ohcount_sourcefile_list_add_directory(sfl, "../gestalt_files/win32_enough"); + LocList *list = ohcount_sourcefile_list_analyze_languages(sfl); + assert(ohcount_loc_list_filecount(list) == 2); + Loc *loc = ohcount_loc_list_get_loc(list, "c"); + assert(loc->code == 2); + assert(loc->comments == 2); + assert(loc->blanks == 2); + ohcount_sourcefile_list_free(sfl); + ohcount_loc_list_free(list); +} + +void test_sourcefile_list_no_symlink_dir() { + SourceFileList *sfl = ohcount_sourcefile_list_new(); + ohcount_sourcefile_list_add_directory(sfl, "../symlink_test_dir"); + LocList *list = ohcount_sourcefile_list_analyze_languages(sfl); + assert(ohcount_loc_list_filecount(list) == 0); + ohcount_sourcefile_list_free(sfl); + ohcount_loc_list_free(list); +} + +#define FALSE 0 +#define TRUE 1 +char *tmp_file_from_buf(const char *buf); + +void test_tmp_dir() { + char buf[] = "This is just some bogus text."; + char *tmp_path = tmp_file_from_buf(buf); + + SourceFileList *list = ohcount_sourcefile_list_new(); + ohcount_sourcefile_list_add_directory(list, "/tmp"); + int has_tmp = FALSE; + SourceFileList *iter = list->head; + + for (; iter != NULL; iter = iter->next) { + if (strcmp(iter->sf->filepath, tmp_path) == 0) { + has_tmp = TRUE; + break; + } + } + assert(has_tmp); +} + + +void all_sourcefile_tests() { + test_sourcefile_initialize(); + test_sourcefile_language_breakdowns(); + test_sourcefile_diff(); + test_sourcefile_calc_diff2(); + test_sourcefile_diff_longer(); + test_sourcefile_diff_very_long(); + test_sourcefile_calc_diff(); + + test_sourcefile_list_language_facts(); + test_sourcefile_list_no_symlink_dir(); + test_tmp_dir(); +} diff --git a/test/unit/sql_test.rb b/test/unit/sql_test.rb deleted file mode 100644 index 353c6ec..0000000 --- a/test/unit/sql_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::SqlTest < Ohcount::Test - - def test_comments - lb = [Ohcount::LanguageBreakdown.new("sql", "", "--comment", 0)] - assert_equal lb, Ohcount::parse(" --comment", "sql") - end - - def test_empty_comments - lb = [Ohcount::LanguageBreakdown.new("sql", "","--\n", 0)] - assert_equal lb, Ohcount::parse(" --\n", "sql") - end - - def test_block_comment - lb = [Ohcount::LanguageBreakdown.new("sql", "","{sql}", 0)] - assert_equal lb, Ohcount::parse(" {sql}", "sql") - end - - def test_comprehensive - verify_parse("sql1.sql") - end - - def test_comment_entities - assert_equal('--comment', entities_array(" --comment", 'sql', :comment).first) - assert_equal('#comment', entities_array(" #comment", 'sql', :comment).first) - assert_equal('//comment', entities_array(" //comment", 'sql', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'sql', :comment).first) - assert_equal('{comment}', entities_array(" {comment}", 'sql', :comment).first) - end - -end diff --git a/test/unit/stratego_test.rb b/test/unit/stratego_test.rb deleted file mode 100644 index 011b4bb..0000000 --- a/test/unit/stratego_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::StrategoTest < Ohcount::Test - def test_line_comments - lb = [Ohcount::LanguageBreakdown.new("stratego", "", "// comment", 0)] - assert_equal lb, Ohcount::parse("// comment", "stratego") - end - - def test_comprehensive - verify_parse("stratego.str") - end - - def test_char_string_entities - assert_equal("'c'", entities_array(" 'c'", 'stratego', :string).first) - # single quote can be used in identiiers - # weak case - assert_not_equal(" c'", entities_array(" c'", 'stratego', :string).first) - # strong case - assert_not_equal("' = e'", entities_array(" c' = e'", 'stratego', :string).first) - end - -end diff --git a/test/unit/tcl_test.rb b/test/unit/tcl_test.rb deleted file mode 100644 index 0ce5b6f..0000000 --- a/test/unit/tcl_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::TclTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("tcl", "", "#comment", 0)] - assert_equal lb, Ohcount::parse(" #comment", "tcl") - end - - def test_comprehensive - verify_parse("tcl1.tcl") - end - - def test_comment_entities - assert_equal('#comment', entities_array(" #comment", 'tcl', :comment).first) - end -end diff --git a/test/unit/tex_test.rb b/test/unit/tex_test.rb deleted file mode 100644 index ff9cda5..0000000 --- a/test/unit/tex_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::TeXTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("tex", "", "%comment", 0)] - assert_equal lb, Ohcount::parse(" %comment", "tex") - end - - def test_comprehensive - verify_parse("foo.tex") - end - - def test_comment_entities - assert_equal('%comment', entities_array(" %comment", 'tex', :comment).first) - end -end diff --git a/test/unit/vala_test.rb b/test/unit/vala_test.rb deleted file mode 100644 index 8acc50f..0000000 --- a/test/unit/vala_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::ValaTest < Ohcount::Test - - def test_comment - lb = [Ohcount::LanguageBreakdown.new("vala", "", "//comment", 0)] - assert_equal lb, Ohcount::parse(" //comment", "vala") - end - - def test_comprehensive - verify_parse("vala1.vala") - end - - def test_comment_entities - assert_equal('//comment', entities_array(" //comment", 'vala', :comment).first) - assert_equal('/*comment*/', entities_array(" /*comment*/", 'vala', :comment).first) - end -end diff --git a/test/unit/vhdl_test.rb b/test/unit/vhdl_test.rb deleted file mode 100644 index ad0cd93..0000000 --- a/test/unit/vhdl_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::VHDLTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("vhdl", "", "-- comment", 0)] - assert_equal lb, Ohcount::parse(" -- comment", "vhdl") - end - - def test_comprehensive - verify_parse("vhdl1.vhd") - end - - def test_comment_entities - assert_equal('--comment', entities_array(" --comment", 'vhdl', :comment).first) - end -end diff --git a/test/unit/vim_test.rb b/test/unit/vim_test.rb deleted file mode 100644 index 265aaeb..0000000 --- a/test/unit/vim_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::VimTest < Ohcount::Test - def test_comprehensive - verify_parse("foo.vim") - end -end diff --git a/test/unit/visual_basic_test.rb b/test/unit/visual_basic_test.rb deleted file mode 100644 index daf90eb..0000000 --- a/test/unit/visual_basic_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::VisualBasicTest < Ohcount::Test - def test_comments - lb = [Ohcount::LanguageBreakdown.new("visualbasic", "", "'comment", 0)] - assert_equal lb, Ohcount::parse(" 'comment", "visualbasic") - end - - def test_comprehensive - verify_parse("frx1.frx") - end - - def test_comment_entities - assert_equal('\'comment', entities_array(" 'comment", 'visualbasic', :comment).first) - assert_equal('Rem comment', entities_array(" Rem comment", 'visualbasic', :comment).first) - end -end diff --git a/test/unit/xml_test.rb b/test/unit/xml_test.rb deleted file mode 100644 index 6153b90..0000000 --- a/test/unit/xml_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::XmlTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("xml", "", "", 0)] - assert_equal lb, Ohcount::parse(" ", "xml") - end - - def test_comprehensive - verify_parse("xml1.xml") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'xml', :comment).first) - end -end diff --git a/test/unit/xmlschema_test.rb b/test/unit/xmlschema_test.rb deleted file mode 100644 index 04ad0b0..0000000 --- a/test/unit/xmlschema_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::XMLSchemaTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("xmlschema", "", "", 0)] - assert_equal lb, Ohcount::parse(" ", "xmlschema") - end - - def test_comprehensive - verify_parse("schema.xsd") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'xmlschema', :comment).first) - end -end diff --git a/test/unit/xslt_test.rb b/test/unit/xslt_test.rb deleted file mode 100644 index 2eed042..0000000 --- a/test/unit/xslt_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Ohcount::XsltTest < Ohcount::Test - def test_comment - lb = [Ohcount::LanguageBreakdown.new("xslt", "", "", 0)] - assert_equal lb, Ohcount::parse(" ", "xslt") - end - - def test_comprehensive - verify_parse("example.xsl") - end - - def test_comment_entities - assert_equal('', entities_array(" ", 'xslt', :comment).first) - end -end