Skip to content

Conversation

Copy link

Copilot AI commented Jul 15, 2025

This PR adds a complete test suite for the copy-as-format package using the ERT (Emacs Regression Testing) framework. The package previously had no tests, making it difficult to verify functionality and catch regressions.

What's Added

  • New file: copy-as-format-tests.el with 48 comprehensive tests
  • Complete format coverage: Tests for all 16 supported formats (asciidoc, bitbucket, disqus, github, gitlab, hipchat, html, jira, markdown, mediawiki, org-mode, pod, rst, telegram, slack, whatsapp)
  • Multiple test scenarios: Single-line and multi-line text formatting where applicable
  • Edge case handling: Empty input, whitespace trimming, special characters
  • Integration testing: Kill ring integration, interactive functions, language detection

Test Categories

Format-Specific Tests (33 tests)

Each format is tested with appropriate scenarios:

;; Example: GitHub format tests
(ert-deftest copy-as-format-test-github-single-line ()
  "Test GitHub format with single line."
  (copy-as-format-tests--test-format "github" "console.log('hello');" nil "`console.log('hello');`"))

(ert-deftest copy-as-format-test-github-multi-line ()
  "Test GitHub format with multiple lines."
  (with-temp-buffer
    (setq buffer-file-name "test.js")
    (let ((text "function hello() {\n  console.log('world');\n}")
          (expected "```js\nfunction hello() {\n  console.log('world');\n}\n```\n"))
      (should (string= (copy-as-format--github text t) expected)))))

Core Functionality Tests (10 tests)

  • Text extraction from buffers and regions
  • Language detection from file extensions
  • Whitespace handling and trimming
  • Special character escaping (HTML entities)

Integration Tests (5 tests)

  • Interactive function existence verification
  • Kill ring integration testing
  • Main function behavior with different formats
  • Format-specific function default setting

Key Features

  • Self-contained: No external dependencies beyond standard Emacs
  • Robust: Handles edge cases like empty input and special characters
  • Comprehensive: Every format in copy-as-format-format-alist is tested
  • Well-documented: Clear test names and helper functions
  • Standards compliant: Uses standard ERT framework conventions

Running the Tests

emacs --batch -l copy-as-format.el -l copy-as-format-tests.el -f ert-run-tests-batch

All 48 tests pass successfully with 0 failures.

Test Coverage Summary

Format Tests Coverage
AsciiDoc 4 Single/multi-line, filename inclusion
Bitbucket 1 Single-line
Disqus 3 Single-line, language detection
GitHub 2 Single/multi-line
GitLab 1 Single-line
HipChat 1 Single-line
HTML 2 Single/multi-line
JIRA 4 Single/multi-line, language mapping
Markdown 2 Single/multi-line
MediaWiki 2 Single/multi-line
Org-mode 2 Single-line, major mode detection
POD 2 Single/multi-line
reStructuredText 3 Single/multi-line, whitespace
Slack 2 Single/multi-line
Telegram 1 Single-line
WhatsApp 1 Single-line

This test suite ensures the reliability and correctness of the copy-as-format package and will help catch regressions in future changes.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

This pull request was created as a result of the following prompt from Copilot chat.

The file copy-as-format.el currently has no tests. We need to add tests for the interactive functions that are generated.

For each format defined in copy-as-format-format-alist, we need to add tests for:

  1. Copying a single line of text.
  2. Copying multiple lines of text, for formats that support it.

The tests should be written using the ert testing framework and placed in a new file named copy-as-format-tests.el.

The file copy-as-format.el can be found at @sshaw/copy-as-format/files/copy-as-format.el.
The tests should cover all formats: asciidoc, bitbucket, disqus, github, gitlab, hipchat, html, jira, markdown, mediawiki, org-mode, pod, rst, telegram, slack, and whatsapp.
The tests should verify that the correct string is added to the kill ring for each format.
The tests should be self-contained and not require any external dependencies beyond what is available in a standard Emacs installation with the copy-as-format package.
The tests should be robust and handle edge cases, such as empty input or input with leading/trailing whitespace.
The test file should be added to the same directory as copy-as-format.el.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add tests for interactive format functions Add comprehensive test suite for copy-as-format package Jul 15, 2025
Copilot AI requested a review from sshaw July 15, 2025 00:38
Copilot finished work on behalf of sshaw July 15, 2025 00:38
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.

2 participants