Skip to content

✨ feat(table): add set_align and test for table alignment#1290

Merged
harehare merged 1 commit intomainfrom
feat/table-align
Feb 17, 2026
Merged

✨ feat(table): add set_align and test for table alignment#1290
harehare merged 1 commit intomainfrom
feat/table-align

Conversation

@harehare
Copy link
Copy Markdown
Owner

  • Add set_align function to table.mq for setting table alignment
  • Add test_table_set_align and test case to module_tests.mq
  • Support to_string for Symbol in builtin.rs

Closes #1188

- Add set_align function to table.mq for setting table alignment
- Add test_table_set_align and test case to module_tests.mq
- Support to_string for Symbol in builtin.rs

Closes #1188
Copilot AI review requested due to automatic review settings February 17, 2026 14:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for setting table column alignments in the mq language. It introduces a new set_align function to the table module, adds Symbol-to-string conversion support for the builtin to_string function, and includes tests for the new functionality.

Changes:

  • Added to_string support for Symbol type in builtin.rs to enable converting symbols (like :left, :center, :right) to their string representations
  • Implemented set_align function in table.mq module to set column alignments using an array of alignment symbols
  • Added test case for the new set_align function in module_tests.mq

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/mq-lang/src/eval/builtin.rs Added Symbol case to TO_STRING builtin to convert symbols to strings without the colon prefix
crates/mq-lang/src/eval.rs Added test case verifying Symbol to_string conversion returns a plain string
crates/mq-lang/modules/table.mq Added set_align function to set table column alignments from an array of alignment symbols
crates/mq-lang/modules/module_tests.mq Added test for set_align function and registered it in the test suite


# Set the alignment for a table.
def set_align(table, align):
set(table, :align, set_attr(table[:align], "align", join(map(align, to_string), ",")))
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set_align function should validate that the length of the align array matches the length of table[:header], similar to how add_row validates row length and add_column validates column length. This prevents setting invalid alignment configurations that don't match the table structure.

For example, you could add validation like:

if (len(align) != len(table[:header])):
  error("Alignment length does not match table header length.")
else:
  # existing implementation
Suggested change
set(table, :align, set_attr(table[:align], "align", join(map(align, to_string), ",")))
if (len(align) != len(table[:header])):
error("Alignment length does not match table header length.")
else:
set(table, :align, set_attr(table[:align], "align", join(map(align, to_string), ",")))
end

Copilot uses AI. Check for mistakes.
| let t1 = table::set_align(t1, [:left, :center, :right])
| assert_eq(to_string(t1[:align]), "|:---|:---:|---:|")
end

Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should verify that the alignment length matches the table header length (3 columns). Add a test case that attempts to set an alignment array with incorrect length to ensure the validation works correctly (once validation is added to the set_align function).

Suggested change
def test_table_set_align_invalid_length():
let t1 = do table::tables(table_nodes) | first();
| let t1 = table::set_align(t1, [:left, :center])
| assert_eq(len(t1[:align]), 3)
end

Copilot uses AI. Check for mistakes.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 17, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/table-align (16a4dab) with main (f34933f)

Open in CodSpeed

@harehare harehare merged commit 32a3240 into main Feb 17, 2026
13 checks passed
@harehare harehare deleted the feat/table-align branch February 17, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement set_align function to set column alignments

2 participants