Commit Graph

9 Commits

Author SHA1 Message Date
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
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
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
254235af47 Fix out of date .exp file.
Estimated hours taken: 0.1
Branches: main

tests/hard_coded/test_pretty_printer.exp:
	Fix out of date .exp file.
2007-08-14 05:23:20 +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