|
| 1 | +import process from "process"; |
| 2 | +import Attribute from '../selectors/attribute'; |
1 | 3 | import {test} from './util/helpers'; |
2 | 4 |
|
| 5 | +process.throwDeprecation = true; |
| 6 | + |
3 | 7 | test('attribute selector', '[href]', (t, tree) => { |
4 | 8 | t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href'); |
5 | 9 | t.deepEqual(tree.nodes[0].nodes[0].type, 'attribute'); |
@@ -393,8 +397,51 @@ test('non standard modifiers', '[href="foo" y]', (t, tree) => { |
393 | 397 | t.deepEqual(tree.toString(), '[href="foo" y]'); |
394 | 398 | }); |
395 | 399 |
|
396 | | -// This is a test case that fails in prettier. Not sure how to support it because I don't know that the range of allowed syntax is. |
397 | | -// And even then, I'm not sure it makes sense. |
398 | | -// test.skip('[nonstandard] function as attribute value', "[id=func('foo')]", (t, tree) => { |
399 | | -// t.deepEqual(tree.toString(), '[href="foo" y]'); |
400 | | -// }); |
| 400 | +test('deprecated constructor', '', (t) => { |
| 401 | + t.throws( |
| 402 | + () => { |
| 403 | + return new Attribute({value: '"foo"', attribute: "data-bar"}); |
| 404 | + }, |
| 405 | + "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now." |
| 406 | + ); |
| 407 | +}); |
| 408 | + |
| 409 | +test('deprecated get of raws.unquoted ', '', (t) => { |
| 410 | + t.throws( |
| 411 | + () => { |
| 412 | + let attr = new Attribute({value: 'foo', quoteMark: '"', attribute: "data-bar"}); |
| 413 | + return attr.raws.unquoted; |
| 414 | + }, |
| 415 | + "attr.raws.unquoted is deprecated. Call attr.value instead." |
| 416 | + ); |
| 417 | +}); |
| 418 | + |
| 419 | +test('deprecated set of raws.unquoted ', '', (t) => { |
| 420 | + t.throws( |
| 421 | + () => { |
| 422 | + let attr = new Attribute({value: 'foo', quoteMark: '"', attribute: "data-bar"}); |
| 423 | + attr.raws.unquoted = 'fooooo'; |
| 424 | + }, |
| 425 | + "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now." |
| 426 | + ); |
| 427 | +}); |
| 428 | + |
| 429 | +test('smart quotes', '[data-foo=bar]', (t, tree) => { |
| 430 | + let attr = tree.nodes[0].nodes[0]; |
| 431 | + attr.setValue('changed', {quoteMark: '"'}); |
| 432 | + t.deepEqual(attr.toString(), '[data-foo="changed"]'); |
| 433 | + attr.setValue('changed again', {quoteMark: "'", preferCurrentQuoteMark: true}); |
| 434 | + t.deepEqual(attr.toString(), '[data-foo="changed again"]'); |
| 435 | + attr.setValue('smart-ident', {smart: true}); |
| 436 | + t.deepEqual(attr.toString(), '[data-foo=smart-ident]'); |
| 437 | + attr.setValue('smart quoted', {smart: true}); |
| 438 | + t.deepEqual(attr.toString(), '[data-foo=smart\\ quoted]'); |
| 439 | + attr.setValue('smart quoted three spaces', {smart: true}); |
| 440 | + t.deepEqual(attr.toString(), '[data-foo="smart quoted three spaces"]'); |
| 441 | + attr.setValue('smart quoted three spaces', {smart: true, quoteMark: "'"}); |
| 442 | + t.deepEqual(attr.toString(), "[data-foo='smart quoted three spaces']"); |
| 443 | + attr.setValue("smart with 'single quotes'", {smart: true}); |
| 444 | + t.deepEqual(attr.toString(), "[data-foo=\"smart with 'single quotes'\"]"); |
| 445 | + attr.setValue('smart with "double quotes"', {smart: true}); |
| 446 | + t.deepEqual(attr.toString(), "[data-foo='smart with \"double quotes\"']"); |
| 447 | +}); |
0 commit comments