Formatter Test Specifications

Test cases for formatting TON documents in different styles (pretty, compact, etc.).

Test Case: FORMATTER_001 - Pretty Format

Purpose

Test formatting with pretty style (indentation, headers, type hints).

Input (Unformatted)

{
name='TestApp',version=1.5,enabled=true,database={host='localhost',port=5432,ssl=true},features=|auth|logging|,endpoints=[{path='/api/users',method='GET',auth=true},{path='/api/health',method='GET',auth=false}]
}

Expected Output (Pretty)

#@ tonVersion = '1'

{
    name = $'TestApp',
    version = %1.5,
    enabled = true,

    database = {
        host = $'localhost',
        port = %5432,
        ssl = true
    },

    features = |auth|logging|,

    endpoints = [
        {
            path = $'/api/users',
            method = $'GET',
            auth = true
        },
        {
            path = $'/api/health',
            method = $'GET',
            auth = false
        }
    ]
}

Validation Points

  • Header with tonVersion included
  • 4-space indentation
  • Type hints ($ for strings, % for numbers)
  • Proper line breaks and spacing
  • Nested structures indented correctly

Test Case: FORMATTER_002 - Compact Format

Purpose

Test formatting with compact style (single line, no extras).

Input (Same as FORMATTER_001)

{
name='TestApp',version=1.5,enabled=true,database={host='localhost',port=5432,ssl=true},features=|auth|logging|
}

Expected Output (Compact)

{name = 'TestApp', version = 1.5, enabled = true, database = {host = 'localhost', port = 5432, ssl = true}, features = |auth|logging|}

Validation Points

  • No header
  • No indentation
  • No line breaks
  • No type hints
  • Minimal spacing

Test Case: FORMATTER_003 - Default Format

Purpose

Test that default formatting uses pretty style.

Input

{value=42}

Expected Output (Default = Pretty)

#@ tonVersion = '1'

{
    value = %42
}

Validation Points

  • Default format same as pretty
  • Header included
  • Indentation applied

Test Case: FORMATTER_004 - Invalid Input

Purpose

Test error handling for invalid TON content.

Input

{ invalid syntax here }

Expected Result

  • Throws parse exception
  • Error indicates syntax problem
  • No partial formatting attempted

Test Case: FORMATTER_005 - Multi-line Strings

Purpose

Test formatting preservation of multi-line strings.

Input

{
    description = 'Simple description',
    value = 42
}

Expected Output (Pretty)

#@ tonVersion = '1'

{
    description = $'Simple description',
    value = %42
}

Validation Points

  • String content preserved
  • Type hints added in pretty format

Test Case: FORMATTER_006 - File Formatting

Purpose

Test formatting from file input.

Operations

  1. Write unformatted TON to temp file
  2. Call format with file path
  3. Read formatted result

Expected Result

  • File read successfully
  • Content formatted correctly
  • Result matches string formatting

Test Case: FORMATTER_007 - Complex Nested Structure

Purpose

Test formatting of deeply nested structures.

Input

{a={b={c={d={e='deep'}}}}}

Expected Output (Pretty)

#@ tonVersion = '1'

{
    a = {
        b = {
            c = {
                d = {
                    e = $'deep'
                }
            }
        }
    }
}

Validation Points

  • Each level indented 4 spaces
  • Closing braces aligned correctly
  • 5 levels of nesting handled

Test Case: FORMATTER_008 - All Data Types

Purpose

Test formatting of all supported data types.

Input

{str='text',num=123,float=45.67,bool=true,nil=null,undef=undefined,guid=550e8400-e29b-41d4-a716-446655440000,enum=|value|,date='2024-01-15T10:30:00Z',hex=0xFF,bin=0b1010,arr=[1,2,3]}

Expected Output (Pretty)

#@ tonVersion = '1'

{
    str = $'text',
    num = %123,
    float = %45.67,
    bool = true,
    nil = null,
    undef = undefined,
    guid = 550e8400-e29b-41d4-a716-446655440000,
    enum = |value|,
    date = $'2024-01-15T10:30:00Z',
    hex = 0xFF,
    bin = 0b1010,
    arr = [1, 2, 3]
}

Validation Points

  • Each type formatted correctly
  • Type hints where appropriate
  • Special formats preserved (hex, binary)

Test Case: FORMATTER_009 - Class Names

Purpose

Test formatting of objects with class names.

Input

{(user)name='John',{(address)street='Main St'}}

Expected Output (Pretty)

#@ tonVersion = '1'

{(user)
    name = $'John',

    {(address)
        street = $'Main St'
    }
}

Validation Points

  • Class names preserved
  • Proper placement after opening brace
  • Child objects formatted correctly

Test Case: FORMATTER_010 - Comments Preservation

Purpose

Test that comments are preserved during formatting.

Input

// Header comment
{
    name = 'test', // inline comment
    /* block comment */
    value = 42
}

Expected Output

Comments preserved in same positions with proper indentation.

Format Styles

Style Description Features
Pretty Human-readable format Indentation, headers, type hints, spacing
Compact Minimal format Single line, no extras
Default Same as Pretty All pretty format features

Implementation Notes

  • Formatter should parse then re-serialize
  • Preserve semantic meaning of all data
  • Handle both synchronous and async operations
  • Support streaming for large documents
  • Maintain consistent spacing and indentation

Error Handling

  • Null input throws ArgumentNullException
  • Invalid syntax throws ParseException
  • File not found throws FileNotFoundException
  • IO errors propagated appropriately