Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
Add tests to make sure valid `code-lang` attributes are kept and invalid ones removed.

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
  • Loading branch information
Plastikmensch committed Nov 3, 2023
1 parent da924c7 commit 4b77682
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/lib/advanced_text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
it 'does not format links' do
expect(subject).to include 'return 0; // https://joinmastodon.org/foo'
end

context 'with valid language' do
let(:text) { "test\n\n```c++\nint main(void) {\n return 0; // https://joinmastodon.org/foo\n}\n```\n" }

it 'formats code using <pre> and <code> with data containing set language' do
expect(subject).to include '<pre><code data-codelang="c++">int main'
end
end
end

context 'with a link in inline code using backticks' do
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/sanitize_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
it 'keeps title in abbr' do
expect(Sanitize.fragment('<abbr title="HyperText Markup Language">HTML</abbr>', subject)).to eq '<abbr title="HyperText Markup Language">HTML</abbr>'
end

it 'keeps data-codelang attribute in code' do
expect(Sanitize.fragment('<code data-codelang="c++">int main(void) { return 0; // https://joinmastodon.org/foo }</code>', subject)).to eq '<code data-codelang="c++">int main(void) { return 0; // https://joinmastodon.org/foo }</code>'
end

it 'removes data-codelang attribute in code when unsupported' do
expect(Sanitize.fragment('<code data-codelang="invalid">int main(void) { return 0; // https://joinmastodon.org/foo }</code>', subject)).to eq '<code>int main(void) { return 0; // https://joinmastodon.org/foo }</code>'
end
end

describe '::MASTODON_OUTGOING' do
Expand Down

0 comments on commit 4b77682

Please sign in to comment.