Commit Graph

12 Commits

Author SHA1 Message Date
Zoltan Somogyi
2bd7c5ee3e Rename X's aux modules as X_helper_N in hard_coded.
tests/hard_coded/*.m:
    Rename modules as mentioned above.

    In a few cases, where the main module's name itself had a suffix,
    such as "_mod_a" or "_main", remove that suffix. This entails
    renaming the .exp file as well. (In some cases, this meant that
    the name of a helper module was "taken over" by the main module
    of the test case.)

    Update all references to the moved modules.

    General updates to programming style, such as

    - replacing DCG notation with state var notation
    - replacing (C->T;E) with (if C then T else E)
    - moving pred/func declarations to just before their code
    - replacing io.write/io.nl sequences with io.write_line
    - replacing io.print/io.nl sequences with io.print_line
    - fixing too-long lines
    - fixing grammar errors in comments

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
    Update all references to the moved modules.

    Enable the constant_prop_int test case. The fact that it wasn't enabled
    before is probably an accident. (When constant_prop_int.m was created,
    the test case was added to a list in the Mmakefile, but that list
    was later removed due to never being referenced.)

tests/hard_coded/constant_prop_int.{m,exp}:
    Delete the calls to shift operations with negative shift amounts,
    since we have added a compile-time error for these since the test
    was originally created.
2023-06-16 08:33:22 +02:00
Zoltan Somogyi
8e6912fe30 Add a more controllable test of terms with operators. 2022-08-29 22:24:09 +10:00
Zoltan Somogyi
8da84c4ee5 Make test_pretty_printer's output more checkable.
tests/hard_coded/test_pretty_printer.m:
tests/hard_coded/test_pretty_printer_helper.m:
    This test checks the operation of the library's pretty_printer module

    - on several docs, and
    - with several parameters.

    With the old organization of this test case, the output consisted of

    - all docs with the first set of parameter values,
    - all docs with the next set of parameter values,
    and so on.

    This diff reorders the output so that it now consists of

    - the first doc with all sets of parameter values,
    - the next doc with all sets of parameter values,
    and so on.

    This makes it much easier to check the output.

    The new approach also

    - gives a name to each doc,
    - prints the doc using the largest parameter values (longest lines,
      most lines allowed, etc) first, which allows all the later outputs
      for the same doc with smaller parameters values to be checked against
      it more easily.

    This diff also moves the code that serves as the infrastructure
    of the test case to the new module test_pretty_printer_helper.m,
    leaving test_pretty_printer.m to contain just the code that
    constructs the docs whose prettyprinting is to be tested. (Previously,
    these two classes of code were interleaved in the source code.)

tests/hard_coded/test_pretty_printer.exp:
    Expect the output in the updated order.
2022-07-25 07:13:17 +10:00
Zoltan Somogyi
0d13ab5e18 Improve the interface of pretty_printer.m.
library/pretty_printer.m:
    Make the changes indicated by the NOTE_TO_IMPLEMENTORS notes
    in my previous change.

NEWS:
    Announce the changes.

browser/browse.m:
tests/hard_coded/test_pretty_printer.m:
    Conform to the above change.
2016-08-09 02:42:00 +02:00
Zoltan Somogyi
33eb3028f5 Clean up the tests in half the test directories.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the debugger tests,
    specify the new line numbers in .inp files and expect them in .exp files.
2015-02-14 20:14:03 +11:00
Peter Wang
0d5b044452 Fix some problems with non-ASCII strings.
Branches: main

Fix some problems with non-ASCII strings.

compiler/error_util.m:
	Make string formatting routines count code points instead of code
	units.

	Iterate over non-ASCII strings correctly.

compiler/llds_out_data.m:
compiler/stack_layout.m:
	Explicitly count UTF-8 code units when counting the length of strings
	that will be written to C source files, in case the compiler is built
	in a grade which uses some other encoding. (The length argument to
	the `MR_string_const' macro isn't actually used, so that change won't
	have any practical effect.)

compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/structure_reuse.direct.choose_reuse.m:
	Fix some code unit counts which should be code point counts.

compiler/make.m:
	Iterate over non-ASCII characters correctly.

compiler/passes_aux.m:
	Simplify the implementation of `stage_num_str'.

compiler/timestamp.m:
	Make `string_to_timestamp' handle non-ASCII strings cleanly,
	although they should never occur.

compiler/x86_64_out.m:
	Split long comments at code point boundaries.

compiler/elds_to_erlang.m:
compiler/erl_code_gen.m:
compiler/mlds_to_cs.m:
compiler/pickle.m:
compiler/switch_util.m:
	Add some comments relating to non-ASCII characters.

library/parsing_utils.m:
	Fix the string and keyword parsers to work on non-ASCII characters.

library/pprint.m:
library/pretty_printer.m:
	Fix code unit counts which should be code point counts.

library/string.m:
	Add `count_utf8_code_units'.

	Fix the portable implementation of `string.to_char_list' (not
	actually used) to work on non-ASCII strings.

	Make string formatting routines count code points instead of code
	units.

library/term_io.m:
	Use a direct string comparison to check string is non-empty.

tests/general/test_parsing_utils.exp:
tests/general/test_parsing_utils.m:
tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	Test non-ASCII strings.
2011-05-17 05:37:30 +00:00
Ralph Becket
65bdaff280 Add a new doc constructor, hard_nl, which always causes a newline
library/pretty_printer.m:
	Add a new doc constructor, hard_nl, which always causes a newline
	(and indentation) to be printed.

	Change the behaviour of the nl constructor so that a newline is
	only started if it increases the amount of space on the line for
	output.

tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	Update the indentation test (the new nl behaviour gives different
	output).
2009-05-18 05:55:14 +00:00
Ralph Becket
642fd27303 Fix a bug in the pretty printer for arbitrary terms where it would not
Estimated hours taken: 0.2
Branches: main

library/pretty_printer.m:
	Fix a bug in the pretty printer for arbitrary terms where it would not
	start a new line for a functor that could not fit on the remainder of
	the line.  This made it impossible to see structure from indentation in
	some cases.

tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	Update the test case.
2009-05-13 01:44:40 +00:00
Julien Fischer
f6739f3185 Fix some failing test cases.
Estimated hours taken: 0.1
Branches: main

Fix some failing test cases.

tests/hard_coded/test_pretty_printer.m:
tests/hard_coded/test_pretty_printer_defaults.m:
	Conform to recent changes to the pretty_printer module.
2007-10-19 05:17:18 +00:00
Ralph Becket
8cbc6b8631 Support pretty-printing the structure of non-canonical values.
Estimated hours taken: 1
Branches: main

library/pretty_printer.m:
	Rename the format preds to write_doc.

	Add an argument to the fully parameterised version of write_doc
	specifying whether non-canonical terms should be handled by
	just printing the type name and arity (`canonicalize') or by
	showing their structure (`include_details_cc').

	Make the canonicalize version det and the include_details_cc version
	cc_multi and propagate the mode changes and extra argument
	through the code.

browser/browse.m:
	Call the new version of write_doc with include_details_cc in a
	promise_equivalent_solutions scope (this is sound because we're writing
	to stdout).

tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	Update the test case to include a non-canonical type.
2007-10-15 04:27:23 +00:00
Ralph Becket
b76b3d5e2b The depth limit was being prematurely decremented when formatting
Estimated hours taken: 1
Branches: main

library/pretty_printer.m:
	The depth limit was being prematurely decremented when formatting
	terms, causing one too few functors to be displayed before
	truncation.  This bug caused everything to be printed as "..."
	at depth 1, rather than just showing the top-level functor.

tests/debugger/browse_pretty.exp:
tests/debugger/browser_test.exp3:
tests/debugger/declarative/sort.exp:
tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer_defaults.exp:
	Update expected output files.

tests/hard_coded/test_pretty_printer.m:
	Test the depth=1 case.
2007-09-02 22:43:03 +00:00
Ralph Becket
751860a6a7 Add a new, improved pretty printer to the library.
Estimated hours taken: 30
Branches: main

Add a new, improved pretty printer to the library.  The key advantages over
pprint are
- better performance on large terms;
- better output (line overruns are completely avoided where possible);
- better control (now supports maximum lines output and two different
  styles of limit on how deeply formatting of arbitrary terms can go);
- support for user-specifiable formatting for arbitrary types.

TODO: update parts of the compiler and debugger that use pprint to use
pretty_printer instead.

NEWS:
	Mention the new change.

library/library.m:
	Add pretty_printer.m.

library/pprint.m:
	Add a comment to say this module has been superceded.

library/pretty_printer.m:
	Added.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	A test suite.
2007-08-03 05:18:39 +00:00